<template>
    <view>
        <view class="load_before flex column" v-if="hideOver1" :style="{opacity: loadOver1 ? 1 : 0}">
            <image class="img2" src="../../static/loading.gif"></image>
            <view class="text">加载中...</view>
        </view>
        <view class="header_content">
            <!-- #ifdef MP-WEIXIN -->
            <view class="reser_top_out" >
                <view v-if="storeInfo.reserve_start != 0 && storeInfo.disable" class="reser_top" :style="{height:navH +'px'}">
                    <view :style="{marginTop:n + 'px'}">
                        预定中，{{storeInfo.reserve_start}}开始
                        <text v-if="storeInfo.open_oneself==2">取餐</text>
                        <text v-else-if="storeInfo.open_oneself==1">配送/取餐</text>
                        <text v-else>配送</text>
                    </view>
               </view>
            </view>
            <block v-if="sid == 'share' || sid == 'qrcode' || sid == 'share_group' || sid == 'buy_together'">
                <top-nav :inner-title="storeInfo.shop_name" is-show-home="true" is-fixed="false" :n=" storeInfo.reserve_start != 0 && storeInfo.disable ? (header=='buy_together' ? 0 : 15 ) : n " :navH=" storeInfo.reserve_start != 0 && storeInfo.disable ? 50 : navH " is-white="bg-gray" opacity="1"></top-nav>
            </block>
            <block v-else>
                <top-nav :inner-title="storeInfo.shop_name" is-show-back="true" is-fixed="false" :n=" storeInfo.reserve_start != 0 && storeInfo.disable ? (header=='buy_together' ? 0 : 15 ) : n " :navH=" storeInfo.reserve_start != 0 && storeInfo.disable ? 50 : navH " is-white="bg-gray" opacity="1"></top-nav> 
            </block>
            <!-- #endif -->
            <!-- #ifdef MP-ALIPAY -->
            <view class="reser_top_out" >
                <view v-if="storeInfo.reserve_start != 0 && storeInfo.disable" class="reser_top" :style="{height:navH-n +'px'}">
                    <view>
                        接受预定中，{{storeInfo.reserve_start}}开始
                        <text v-if="storeInfo.open_oneself==2">取餐</text>
                        <text v-else-if="storeInfo.open_oneself==1">配送/取餐</text>
                        <text v-else>配送</text>
                    </view>
               </view>
            </view>
            <!-- #endif -->
            
            <block v-if="header == 'buy_together'">
                <view class="buy_together_header header">
                    <view class="buy_together_top flex_Row">
                        <view class="buy_status">拼单进行中</view>
                        <view class="buy_tips flex_Row" @click="buyTogetherShow()">
                            <view class="green_text">
                                <icon class="checked_little"></icon>更优惠
                            </view>
                            <view class="green_text">
                                <icon class="checked_little"></icon>一起送
                            </view>
                            <view class="green_text">
                                <icon class="checked_little"></icon>便捷分账
                            </view>
                        </view>
                    </view>
                    
                    <view class="gray_text" v-if="group_info.info.length>0">
                        <view class="face_content ellipsis">
                            <image class="face" v-for="(item,index) in group_info.info" :key="index" :src="item.face" v-if="index<=5"></image>
                        </view>
                        <view class="ellipsis_dot" v-if="group_info.info.length>5">...</view>
                        <text v-if="group_info.finish>0">{{group_info.finish}}人已点完 </text>
                        <text v-if="group_info.ongoing>0">{{group_info.ongoing}}人正在选购</text>
                    </view>
                    <view class="gray_text" v-else>
                        ...还没有好友加入拼单，快去拼单吧～
                    </view>
                    <view class="buy_buttons">
                        <button class="white_bg" hover-class="none" @click='cancelBuyTogether("cancel")' v-if="is_master">取消拼单</button>
                        <button class="white_bg" hover-class="none" @click='cancelBuyTogether("out")' v-if="!is_master">退出拼单</button>
                        <block v-if="totalCount_all>0">
                            <button class="white_bg" hover-class="none" @click="toggleList()">拼单详情</button>   
                        </block>
                        <block v-else>
                            <button class="white_bg gray" hover-class="none">拼单详情</button>   
                        </block>
                        <button class="green_bg" hover-class="none" open-type="share" data-id="0" v-if="is_master">邀请好友</button>
                    </view>
                </view>
            </block>

            <block v-else>
                <block v-if="storeInfo.open_group_active > 0">
                    <view class="header group_active">
                        <block v-if="currentInfo.is_open>0">
                            <block v-if="currentInfo.current_finishTime || storeInfo.address">
                                <view class="group_notice" @click="showGroupNotice()">
                                    <view class="flex" :class="currentInfo.current_finishTime && storeInfo.address ? 'marquee' : ''">
                                        <view>现在下单，
                                             <block v-if="currentInfo.current_finishTime">
                                                 {{currentInfo.current_finishTime}}送达
                                             </block>
                                            <block v-if="storeInfo.address">
                                                ，{{storeInfo.address}}取餐
                                            </block>
                                        </view>
                                    </view>
                                    <icon class="arr_right_white"></icon>
                                </view>  
                            </block>
                            
                            <view class="active-status">
                                <view class="status-text">{{activeStatusText}}</view>
                                <view class="active-intro" @click="groupRuleEvent()">
                                    <button>开车玩法</button>
                                </view>
                            </view>
                            <view class="active-num">
                                <view class="active-num_left">
                                    <block v-for="(item,index) in personList" :key="index">
                                        <image :src="item == 1?'http://juhuijia2.birdback.org/mapi/i/face1@3x.png':'http://img1.birdback.org/a/6a/a0/6aa0cf34e9be25d552c8614145c9b60a.png'"></image>
                                    </block>
                                    <text @click="showByPerson()">{{activeNumText}}</text>
                                </view>
                                <!-- <text  class="got_time" v-if=" activeNumText=='…开车成功>' ">{{finishTime}} 送达</text> -->
                            </view>
                           
                        </block>
                        <block v-else>
                            <view class="active-status-no">
                                <text>{{activeStatusText}}</text>
                                <button @click="goGroupList">点击查看其他班次</button>
                            </view>
                        </block>        
                    </view>
                </block>
               <block v-else>
                    <view class="header">
                        <view class="content-wrapper" @click="goStoreDetail()">
                            <view class="avatar">
                                <view v-if="storeInfo.reserve_start == 0" class="close"></view>
                                <image :src="storeInfo.icon"></image>
                            </view>
                            <view class="content">
                                <view class="arrow_out_top">
                                    <view class="jiantou"></view>
                                </view>
                                <view class="bulletin-wrapper">
                                    <text v-if="storeInfo.notice">公告：{{storeInfo.notice}}</text>
                                </view>
                                <view class='shop-tags'>
                                    <view class="description flex_Row">
                                        <view class="flex_Row" v-if="storeInfo.start_send_price">
                                            <icon class='start_send_icon'></icon>
                                            <text>起送￥{{storeInfo.start_send_price}}</text>
                                        </view>
                                        <view class="flex_Row" v-if="storeInfo.send_price">
                                            <icon class='send_icon'></icon>
                                            <text>配送￥{{storeInfo.send_price}}</text>
                                        </view>
                                    </view>
                                        <view class="sale_content" v-for='(item,index) in arrAll' :key="index">
                                        {{item}}
                                        </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </block>
            </block>
            <view class="red_packet_content">
                <view class="red_packer_c"  v-if="packetList.length>0"  @click="goStoreDetail()">
                    <block v-for="(item,index) in packetList" :key = "index">
                         <view class="red_packet" :class="item.status == 0 || item.residue_num<=0 ? 'choosed' : 'choosed_wait'">
                            <image v-if="item.status == 0 || item.residue_num<=0" src="http://img1.birdback.org/a/b5/32/b532e24c848810fa251d57f76abc3df2.png"></image>
                            <image  v-else src="http://img1.birdback.org/a/dd/7e/dd7e572eaedda4ba7c40edb6ace2f4bd.png"></image>
                            <view class="red_packet_inner">
                                <view class="packet_num">¥ <text>{{item.reduction}}</text></view>
                                <view class="packet_status">
                                    <block v-if="item.residue_num<=0">
                                        已领完
                                    </block>
                                    <block v-else>
                                        {{item.status == 0 ? '已领':'领取'}}
                                    </block>
                                </view>
                            </view>
                        </view>
                    </block>
                </view>
            </view>
            <!--tab切换-->
            <view class="menu">
                <view data-id="1" @click="tabbarEvent(1)" :class="tabbarId == 1?'ck':''">
                    <text>菜单</text>
                    <icon></icon>
                </view>
                <view data-id="3" @click="tabbarEvent(3)" :class="tabbarId == 3?'ck':''">
                    <text>评价</text>
                    <icon></icon>
                </view>
                <view data-id="2" @click="tabbarEvent(2)" :class="tabbarId == 2?'ck':''">
                    <text>商家</text>
                    <icon></icon>
                </view>
                <view class="search">
                        <view class="search-item" @click="inputSearch()">
                            <image src="http://juhuijia2.birdback.org/mapi/i/run/search@3x.png"></image>
                            <text>搜索</text>
                        </view>
                </view>
            </view>
        </view>
        <!--head -->
       <view :style="{height:storeTop + 'px'}"></view>
        <view class="goods" v-if="tabbarId == 1"  :style="{height: storeHeight + 'px'}">
            <block v-if=" storeInfo.open_group_active > 0 ">
                <view class="active-time">
                    距截单<text>{{activeTime[0]}}</text>:<text>{{activeTime[1]}}</text>:<text>{{activeTime[2]}}</text>
                </view>
            </block>
            <view class="menu-wrapper">
                <block v-if="is_super == 1">
                    <scroll-view scroll-y="true" style="height: 100%;" @scroll="scrollLeft()" :show-scrollbar="showScrollbar" scroll-with-animation=true>
                        <view v-for="(item,index) in categoryList" :key="index" class="menu-item" :class="'order' + index == toView?'current':''"
                              @click="selectMenu($event)" :data-item-index="index">
                            <view class="icon">
                                <view></view>
                            </view>
                            <view class="text">
                                <block v-if="item.tid == 1">
                                    <image src="http://img1.birdback.org/a/86/29/86295971489b6a7d79253af031873714.png"></image>
                                </block>
                                <block v-if="item.tid == 2">
                                    <image src="http://img1.birdback.org/a/a4/13/a4130cf37dc0e0fda8e11e39aa00bb38.png"></image>
                                </block>
                                 <text  class="menu_item_title">{{item.name}}</text>
                            </view>
                            <view class='box'></view>
                            <view class="badge-red flex" v-if="item.count>0 && item.tid==0">{{item.count}}</view>
                        </view>
                        <view class="menu-item"></view>
                    </scroll-view>
                </block>
                <block v-else>
                    <scroll-view scroll-y="true" style="height: 100%;" :scroll-top="left_scroll" @scroll="scrollLeft()" :show-scrollbar="showScrollbar" scroll-with-animation=true>
                        <view class="left-content">
                            <view v-for="(item,index) in categoryList" :key="index" class="menu-item" :class="select_index_ca == index?'current':''" 
                                  @click="choose($event)" :data-item-index="index" :data-name="item.name"  :id="'item_'+index">
                                <view class="icon">
                                    <view></view>
                                </view>
                                <view class="text">
                                    <block v-if="item.tid == 1">
                                        <image src="http://img1.birdback.org/a/86/29/86295971489b6a7d79253af031873714.png"></image>
                                    </block>
                                    <block v-if="item.tid == 2">
                                        <image src="http://img1.birdback.org/a/a4/13/a4130cf37dc0e0fda8e11e39aa00bb38.png"></image>
                                    </block>
                                     <text  class="menu_item_title">{{item.name}}</text>
                                </view>
                                <view class='box'></view>
                                <view class="badge-red flex" v-if="item.count>0 && item.tid==0">{{item.count}}</view>
                            </view>
                            <view class="menu-item"></view>
                        </view>
                    </scroll-view>
                </block>
            </view>
<!--            <scroll-view scroll-y="true" :scroll-top="scrollTop" :scroll-into-view="toView" class="foods-wrapper" style="height: 100%;" @scroll="scrollMove()"> -->
                <view class="foods-wrapper" style="height: 100%;">
                <view class="food-list food-list-hook" style="height: 100%;">
                    <block v-if="is_super == 1">
                        <view class="title flex">
                            <view class="ellipsis">
                                <text>{{categoryInfo.name}}</text>
                            </view>
                        </view>
                        <goods-item 
                            :bang             = "bang"
                            :header           = "header"
                            :goodsList        = "goodsList" 
                            :goodsDetail      = "goodsDetail" 
                            :setting          = "setting" 
                            :goodsId          = "goodsId"
                            :storeHeight      = "storeHeight"
                            :toItem           = "toItem"
                            :scrollTop        = "scrollTop"
                            @addCart          = "addCart()"
                            @decreaseCart     = "decreaseCart()" 
                            @showGoodsDetail  = "showGoodsDetail()"
                            @closeGoodsDetail = "closeGoodsDetail()"
                            @selectSetting    = "selectSetting()"
                            @settingInsert    = "settingInsert()"
                            @addDetailCart    = "addDetailCart()"
                            @closeSetting     = "closeSetting()"
                            @scrollMove       = "scrollLeft()"    
                        >
                        </goods-item>
                    </block>
                    <block v-else> 
                       <!-- <view class="load_before flex" v-if="hideOver" :style="{opacity: loadOver ? 1 : 0}">
                            <view class="text">菜单加载中...</view>
                        </view> -->
                        <view class="title flex">
                            <view class="ellipsis">
                                <block v-if="select_index<0">
                                    <text>{{categoryList[0].name}}</text>
                                </block>
                                <block v-else>
                                    <text>{{categoryList[select_index].name}}</text>
                                </block>
                                
                            </view>
                        </view>
                        <scroll-view scroll-y="true" :scroll-into-view='toItem' :scroll-top="right_scroll" @scroll="scrollMove($event)"  :style="{height:storeHeight-45 + 'px'}" :show-scrollbar="showScrollbar">
                            <view class="category-item" v-for="(item,link) in goodsList" :key="link">
                                    <view class="title flex" v-if="link != 0">
                                        <view class="ellipsis">
                                            <text>{{categoryList[link].name}}</text>
                                        </view>
                                    </view>
                                    <view v-for="(food,index) in item" class="food-item" :key="index" :id="'item_'+food.id">                              
                                        <view class="icon" @click="showGoodsDetail($event)" :data-index="index" :data-link="link">
                                            <image :src="food.icon"></image>
                                        </view>
                                        <view class="content">
                                            <view class="name" :class="food.id==goodsId ? 'green' : '' ">{{food.name}}</view>
                                            <view class="desc">{{food.description}}</view>
                                            <view class="extra">月售{{food.buy_num}}</view>
                                            <view class='price_bar'>
                                              <view class="price">
                                                <view class="now">￥{{food.price}}</view>
                                                <view class="old" v-if="food.show_price > 0">￥{{food.show_price}}</view>
                                              </view>
                                            <!--cartControl-->
                                                <view class="cartControl-wrapper">
                                                    <block v-if=' !storeInfo.disable || storeInfo.reserve_start != 0 '>
                                                        <block v-if="food.sel_out > 0">
                                                            <view style="color:#545455;font-size:30rpx;">已售完</view>
                                                        </block>
                                                        <block  v-else>
                                                            <view class="cartControl">
                                                                <view class="flex">
                                                                    <block  v-if="header == 'buy_together'">
                                                                        <view class="cart-decrease"  v-if="food.self > 0" :data-link="item" :data-id="food.id" :data-index="index" @click="decreaseCart($event)">
                                                                            <view class="inner"></view>
                                                                        </view>
                                                                        <view class="cart-decrease disable" v-if="food.other > 0 && food.self == 0" :data-id="food.id" :data-index="index">
                                                                            <view class="inner"></view>
                                                                        </view>
                                                                        <view class="cart-count" v-if="food.other+food.self > 0 ">
                                                                            {{food.other+food.self}}
                                                                        </view>
                                                                    </block>
                                                                    <block v-else>
                                                                        <view class="cart-decrease" v-if="food.Count > 0"  :data-link="link" :data-id="food.id" :data-index="index" @click="decreaseCart($event)">
                                                                            <view class="inner"></view>
                                                                        </view>
                                                                        <view class="cart-count" v-if="food.Count > 0 ">
                                                                            {{food.Count}}
                                                                        </view>
                                                                    </block>
                                                                    <view class="cart-add" :data-link="link" :data-index="index" :data-id="food.id" @click="addCart($event)"></view>
                                                                </view>
                                                            </view>
                                                        </block>
                                                    </block>
                                                    
                                                </view>
                                             </view>
                                            <block v-if="food.open_discount > 0">
                                                <view class="discount-tag">{{food.discount.discount}}折 {{food.discount.num_discount >
                                                    0?'限'+food.discount.num_discount+'份':''}}
                                                </view>
                                            </block>
                                        </view>
                                    </view>
                            </view>
                            <view :class=" bang ? 'food-item-plank-bang' : 'food-item-plank' "></view>
                        </scroll-view>  
                    </block>
                </view>
            <!-- </scroll-view> -->
            </view>
            <!--shopCart-->
                <shop-cart class="shopCart" 
                    :storeInfo          = "storeInfo"
                    :header             = "header"
                    :disable            = "storeInfo.disable" 
                    :reserve_start      = "storeInfo.reserve_start" 
                    :totalCount         = "totalCount" 
                    :totalCount_all     = "totalCount_all"
                    :totalPrice         = "totalPrice"
                    :totalPrice_all     = "totalPrice_all"
                    :diffPrice          = "diffPrice"
                    :payDesc            = "payDesc"
                    :deliveryPrice      = "deliveryPrice"
                    :open_oneself       = "storeInfo.open_oneself"
                    :cartShow           = "cartShow"
                    :carList            = "carList"
                    :toView             = "toView"
                    :packageFee         = "packageFee"
                    :activeList         = "activeList"
                    :groupList          = "groupList"
                    :self_money         = "self_money"
                    :showGetUser_1      = "showGetUser_1"
                    :is_master          = "is_master"
                    :must               = "must"
                    :showGetUserStorage = "showGetUserStorage"
                    :listServiceType    = "listServiceType"
                    :sid                = "sid"
                    @toggleList         = "toggleList()" 
                    @empty              = "empty()"
                    @addCartGoods       = "addCartGoods()"
                    @subCartGoods       = "subCartGoods()"
                    @pay                = "pay()"
                    @getUserInfo        = "getUserInfo()">
                </shop-cart>
        </view>
         <!--shopCart end-->
        <view class="evaluation" v-if="tabbarId == 3">
            <view class="eva_class flex">
                <block v-if="score>0">
                    <view class="eva_class_left">
                        <view class="red_text">{{score}}</view>
                        <view class="gray_text">商家评分</view>
                    </view>
                     <view class="eva_class_midd">
                        <view class="flex">
                            <view class="gray_text">口味</view>
                            <view class="stars_con flex">
                                <icon v-for="(item, index) in tasteInt" class=" star_yellow" :key="index"></icon>
                                <icon v-if="tasteFloat>0" :class="'star_yellow_'+tasteFloat"></icon>
                                <block v-if="tasteFloat>0">
                                    <icon v-if="5-taste >=1" v-for="(item, index) in 4-tasteInt" class=" star_gray" :key="index"></icon> 
                                </block>
                                <block v-else>
                                    <icon v-if="5-taste >=1" v-for="(item, index) in 5-tasteInt" class=" star_gray" :key="index"></icon> 
                                </block>
                                 
                            </view>
                            <view class="yellow_text">{{taste}}</view>
                        </view>
                        <view class="flex">
                            <view class="gray_text">包装</view>
                            <view class="stars_con flex">
                                <icon v-for="(item, index) in packInt" class="star_yellow" :key="index"></icon>
                                <icon v-if="packFloat>0" :class="'star_yellow_'+packFloat"></icon>
                                <block v-if="packFloat>0">
                                    <icon v-if="5-pack >=1" v-for="(item, index) in 4-packInt" class="star_gray" :key="index"></icon>
                                </block>
                                <block v-else>
                                    <icon v-if="5-pack >=1" v-for="(item, index) in 5-packInt" class="star_gray" :key="index"></icon>
                                </block>
                                
                            </view>
                            <view class="yellow_text">{{pack}}</view>
                        </view>
                    </view>
                    <!-- <view class="eva_class_right flex">
                        <view class="slide"></view>
                        <view class="slide_right">
                            <view class="light_text big">{{on_time}}</view>
                            <view class="light_text">配送满意度</view>
                        </view>                     
                    </view> -->
                </block>
                <block v-else>
                    <view class="score_empty flex">
                        <view class="score_empty_icon"></view>
                        <view class="">
                            <view class="dark_text">近期的评价不足，无法计算综合得分</view>
                            <view class="gray_text">亲，在订单确认送达后记得来评价哦～</view>
                        </view>
                    </view>
                </block>
            </view>
            <view class="eva_content">
                <view class="eva_bts">
                    <view class="green_bt gray_text" :class="s_type == 1 ? 'ck' : ''" @click="typeEvaluation(1)">全部 {{eva_count}}</view>
                    <view class="green_bt gray_text" :class="s_type == 2 ? 'ck' : ''" @click="typeEvaluation(2)">最新</view>
					 <view class="green_bt gray_text" :class="s_type == 6 ? 'ck' : ''" @click="typeEvaluation(6)">有图 {{eva_image_count}}</view>
                    <view class="green_bt gray_text" :class="s_type == 3 ? 'ck' : ''" @click="typeEvaluation(3)">好评 {{eva_good_count}}</view>
                    <view class="green_bt gray_text" :class="s_type == 5 ? 'ck' : ''" @click="typeEvaluation(5)">中评 {{eva_middle_count}}</view>
                    <view class="gray_bt light_text" :class="s_type == 4 ? 'ck' : ''" @click="typeEvaluation(4)">差评 {{eva_bad_count}}</view>
                </view>
                <view class="eva_tip flex" @click="showContent()">
                    <view class="ck-icon" :class="is_content==2 ? 'checked':'eval'"></view>
                    <view class="gray_text">只看有内容的评价</view>
                </view>
                <scroll-view @scrolltolower="updateEvalList">
                    <view class="eva_list flex" v-for="(item,index) in eval_list" :key="index"  v-if="eval_list.length>0">
                        <image class="img" :src="item.face"></image>
                        <view class="item_right">
                            <view class="item_row flex">
                                <view class="name ellipsis dark_text">{{item.user_name}}</view>
                                <view class="light_text">{{item.add_time}}</view>
                            </view>
                            <view class="item_row eva_grade flex">
                                <view class="light_text">评分</view>
                                <view class="stars_con flex" v-for="index in 5" :key="index" >
                                    <icon :class="item.score > index ? 'star_yellow' : 'star_gray'"></icon>
                                </view>
                            </view>
                            <view class="item_row eva_val dark_text">{{item.desc}}</view>
                            <!-- <view class="item_row flex">
                                <icon class="good_icon"></icon>
                                <view class="good_item gray_text">夏威夷披萨</view>
                                <view class="good_item gray_text">夏威夷披萨</view>
                                <view class="good_item gray_text">夏威夷披萨</view>
                                <view class="good_item gray_text">夏威夷披萨</view>
                            </view> -->
                            <view class="item_row">
                                <image class="eva_image" v-for="(mitem,index) in item.image" :src="mitem" :data-id="item.image" @click="imgMap(index,$event)"  mode="aspectFill"  lazy-load="true"></image>
                            </view>
                            <view class="item_row eva_back" v-if="item.store_reply">
                                商家回复：{{item.store_reply}}
                            </view>
                        </view>
                    </view>
                    <view class="no-more" v-if="noMore">没有更多评价了</view>
                </scroll-view>
            </view>
        </view>
    <!--tab商家信息-->
        <view class="fujia" v-if="tabbarId == 2">
            <view class='option'>
                <view class='item'>
                    <view>
                        <text class="a1">商家信息</text>
                    </view>
                    <text></text>
                </view>
            </view>
            <view class='option'>
                <view class='item'>
                    <view>
                        <text>营业时间</text>
                    </view>
                    <text>{{storeInfo.disable_time}}</text>
                </view>
            </view>
            <view class='option'>
                <view class='item' @click="goMobile">
                    <view>
                        <text>联系电话</text>
                    </view>
                    <text style="flex: 1;color: #4B76FF;">{{storeInfo.mobile}}</text>
                    <icon class="arr_right"></icon>
                </view>
            </view>
            <view class='option'>
                <view class='item' @click="goCertificate()">
                    <view>
                        <text>营业资质</text>
                    </view>
                    <text style="flex: 1;color: #4B76FF;"></text>
                    <icon class="arr_right"></icon>
                </view>
            </view>
        </view>
        
        <view class="setting-box" v-if="setting.show">
            <view class='setting-mask' @click='closeSetting()'></view>
            <view class='setting-view'>
                <image class="close_icon" @click='closeSetting()' src="http://img1.birdback.org/a/0d/08/0d086db73d634f97c3940279c2ebbdd3.png"></image>
                <view class='setting-head'>
                    <!-- <view class='close' @click='closeSetting()'></view> -->
                    <view class='title'>
                        <text>{{setting.name}}</text>
                    </view>
                </view>
                <view class='setting-item'>
                    <scroll-view scroll-y style="max-height: 600rpx;" :scroll-top="scollTop">
                        <block v-for='(item,idx) in setting.item' :key="idx">
                            <view class='item'>
                                <view class='title flex'>{{item.name}}</view>
                                <view class='button-list'>
                                    <block v-for='(list,index) in item.value' :key="index">
                                        <block v-if="item.type == 'spec' && list.num <= 0">
                                            <view>{{list.name}}(已售完)</view>
                                        </block>
                                        <block v-else>
                                            <view  :class='list.current == 1 ? "ck" : ""' @click='selectSetting($event)' :data-link='link' :data-idx='idx' :data-index='index'>{{list.name}}
                                            </view>
                                        </block>
                                    </block>
                                </view>
                            </view>
                        </block>
                    </scroll-view>
                    <view class='setting-price'>
                        <text v-if="setting.price > 0">￥{{setting.price}}</text>
                        <text class="old" v-if="setting.showPrice > 0">￥{{setting.showPrice}}</text>
                        <view @click='settingInsert()'>选好了</view>
                    </view>
                </view>
            </view>
        </view>
        
         <view class="goodsDetail-box" v-if="goodsDetail.show">
            <view class='goodsDetail-mask' @click="closeGoodsDetail()"></view>
            <view class='goodsDetail-content'>
                <view class="goodsDetail-image">
                    <image :src="goodsDetail.src"></image>
                    <text class="goodsDetail-title">{{goodsDetail.title}}</text>
                    <text class="goodsDetail-info">{{goodsDetail.info}}</text>
                    <text class="goodsDetail-num">月售{{goodsDetail.num}}份</text>
                    <text class="goodsDetail-price">￥{{goodsDetail.price}}</text>
                    <view class="goodsDetail-status">
                        <block v-if='!storeInfo.disable'>
                            <block v-if="goodsDetail.sel_out > 0">
                                <view style="color:#545455;font-size:30rpx;">已售完</view>
                            </block>
                            <block v-else>
                                <view class="goodsDetail-add" :data-index="goodsDetail.index" :data-link="goodsDetail.link" @click="addDetailCart($event)"></view>
                            </block>
                        </block>
                    </view>
                </view>
                <view class='close_together' @click="closeGoodsDetail()"> </view>  
            </view>
        </view>
        
    <!--开车按钮 -->
    <!-- #ifdef MP-WEIXIN -->
    
    <block v-if="tabbarId == 1">
        <block v-if=" storeInfo.open_group_active > 0 ">
            <view class="group_share_button">
                <button open-type="share" hover-class="none" data-id="2"></button>
            </view>
        </block>
        <block v-else>
            <block v-if="groupOpen">
                <view class="navigation_icon" :class=" navigationClose || header == 'buy_together' ? '' : 'share_together' ">
                    <!-- 拼单按钮 -->
                    <block v-if=" (!storeInfo.disable || storeInfo.reserve_start != 0 ) && header !='buy_together' " >
                           <!-- <block v-if=" showGetUser_1 && showGetUserStorage == '0' ">
                                <button class='group_together_button s1' hover-class="none" @click=" buyTogetherShow()" v-if="!navigationClose || header == 'buy_together' ">
                                    <image v-if="navigationClose" src="http://img1.birdback.org/a/00/b1/00b19a232c560514e350822352c08693.png"></image>
                                </button> 
                                <button class='group_together_button s3' hover-class="none" @click="openNavigation()" v-else>
                                    <image v-if="navigationClose" src="http://img1.birdback.org/a/00/b1/00b19a232c560514e350822352c08693.png"></image>
                                </button> 
                            </block>-->
                            
                            <block v-if="!navigationClose || header == 'buy_together'">
                                <button  class="group_together_button s2" hover-class="none" :open-type="!navigationClose || header == 'buy_together' ? 'share' : ''" data-id="01"  >
                                    <image v-if="navigationClose" src="http://img1.birdback.org/a/00/b1/00b19a232c560514e350822352c08693.png"></image>
                                </button>
                            </block>
                            <block v-else>
                                <button  class="group_together_button s2" hover-class="none" data-id="01" @click="openNavigation()" >
                                    <image v-if="navigationClose" src="http://img1.birdback.org/a/00/b1/00b19a232c560514e350822352c08693.png"></image>
                                </button>
                            </block>
                    </block> 
    
                    <!--分享按钮 开车没有-->
                    <block v-if=" storeInfo.open_group_active == 0 ">
                            <view class="share" :class=" navigationClose || header == 'buy_together' ? 'bg' :''">
                                <button open-type="share" data-id="1" hover-class="none"></button>
                            </view>

                    </block>
                    <view v-if="!navigationClose" class='close_navigation' @click='closeNavigation()'></view>
                </view>
            </block>
            <block v-else>
                <block v-if=" sid != 'group' && sid != 'share_group'">
                    <view class="navigation_icon">
                        <view class="share bg">
                            <button open-type="share" data-id="1" hover-class="none"></button>
                        </view>
                    </view>
                </block>
            </block>
        </block>
    </block>
    <!-- #endif -->
    
    <!--必选按钮 -->
    <block v-if="is_super == 0">
        <image class="must-choose-icon" v-if=" must && categoryInfo.cid != mustCid && tabbarId == 1 && select_index != mustClistKey" @click="getMust()" src="http://img1.birdback.org/a/ab/38/ab38a27967a8c90705713383c5500779.png"></image>
    </block>
    <block v-else>
        <image class="must-choose-icon" v-if=" must && categoryInfo.cid != mustCid && tabbarId == 1" @click="getMust()" src="http://img1.birdback.org/a/ab/38/ab38a27967a8c90705713383c5500779.png"></image>
    </block>
    
    <!-- #ifdef MP-WEIXIN -->
    <!-- 拼单弹窗 -->
    <view class="group-detail-box" v-if=" showBuyTogether ">
        <view class="group-mask"  @touchmove.stop.prevent="moveHandle"></view>
        <view class="group-detail-medium">
            <view class='list'>  
                <block v-if=" showGetUser_1 && showGetUserStorage == '0' ">
                    <button class="weChat_share" hover-class="none" open-type="getUserInfo" @getuserinfo="getUserInfo"  data-id="0"></button>
                </block>
                <block v-else>
                    <button class="weChat_share" hover-class="none" open-type="share"  data-id="0"></button>
                </block>
            </view>
            <view class='close_together' @click="buyTogetherClose()"> </view>
        </view>
    </view>

    <view class='group-detail-box' v-if="showCheckGroup">
        <view class="group-mask"  @touchmove.stop.prevent="moveHandle"></view>
        <view class="group-detail-medium white_bg">
            <view class='title'>好友仍在选购中</view>
            <view class="content">{{stillCheckList.length}}位好友还在选购，现在结算会导致好友无法继续选购</view>
            <view class="list-item flex_Row" v-for="(item,index) in stillCheckList" :key="index">
                <image class="face" :src="item.face"></image>
                <view class="name ellipsis">{{item.nickname}}</view>
            </view>
            <view class="bottom flex_Row">
                <button class="black_text" hover-class="none" @click="toPayFunc()">去结算</button>
                <button class="green_text" hover-class="none" @click="closeCheckGroup()">再等等</button>
            </view>
        </view>
    </view>
    <!-- #endif -->
    
    <!--开车玩法弹窗-->
    <view class="group-detail-box" :style="{top:showGroupRule ? '0' : '100%'}">
        <view class='group-mask' @click="groupRuleClose1()"></view>
        <view class='group-detail'>
            <view class="group-detail-title">开车玩法介绍</view>
            <view class="group-detail-list">
                <view class="group-item">
                    <image src="http://juhuijia2.birdback.org/mapi/i/home2/rule1@3x.png"></image>
                    <text>选择商品，开车或拼车</text>
                </view>
                <view class="group-item">
                    <image src="http://juhuijia2.birdback.org/mapi/i/home2/rule2@3x.png"></image>
                    <text>付款后邀请好友参与开车</text>
                </view>
                <view class="group-item">
                    <image src="http://juhuijia2.birdback.org/mapi/i/home2/rule3@3x.png"></image>
                    <text>达到开车人数，顺利开车</text>
                </view>
                <view class="group-item">
                    <image src="http://juhuijia2.birdback.org/mapi/i/home2/rule4@3x.png"></image>
                    <text>开车成功后，订单不可取消</text>
                </view>
                <view class="group-item">
                    <image src="http://juhuijia2.birdback.org/mapi/i/home2/rule5@3x.png"></image>
                    <text>规定时间内，开车不成功全额退款</text>
                </view>
            </view>
        </view>
    </view>
    
    <view class="group-detail-box" v-if="showStoreInfo">
        <view class="group-mask" @touchmove.stop.prevent="moveHandle"></view>
        <view class="group-detail-medium store_info">
            <view class="list">  
               <view class="store_info">
                   <view class="store_name ellipsis">{{storeInfo.shop_name}}</view>
                   <view class="info_title" v-if="packetList.length>0">满减券</view>
                   <view class="coupon_out" v-if="packetList.length>0">
                        <block  v-for="(item,index) in packetList" :key = "index">
                            <view class="coupon">
                               <view :class="item.status == 0 || item.residue_num<=0 ? 'coupon_chosed' : 'coupon_wait'">
                                       <view class="coupon_left">
                                              <view class="coupon_value">¥<text>{{item.reduction}}</text></view>
                                              <view class="ellipsis">满{{item.full}}元可用</view>
                                              <view class="ellipsis">有效期至{{item.end_time}}}</view>
                                       </view>
                                       <block v-if="item.residue_num<=0">
                                            <view class="coupon_right flex">已领完</view>
                                       </block>
                                       <block v-else>
                                           <block v-if="isRegisted">
                                               <view class="coupon_right flex" @click="getPacket(item.id)">
                                                    {{item.status == 0 ? '已':''}}领取
                                               </view>
                                            </block>
                                            <block v-else>
                                                <block v-if="bindPhone == 1">
                                                    <view class="coupon_right flex" @click="loadNewPacket(item.id)">
                                                         {{item.status == 0 ? '已':''}}领取
                                                    </view>
                                                </block>
                                                <block v-else>
                                                    <!-- #ifdef MP-WEIXIN -->
                                                     <button class="coupon_right flex" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
                                                         {{item.status == 0 ? '已':''}}领取
                                                     </button>  
                                                    <!-- #endif -->
                                                    <!-- #ifdef MP-ALIPAY -->
                                                     <button class="coupon_right flex" open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>
                                                         {{item.status == 0 ? '已':''}}领取
                                                     </button>  
                                                    <!-- #endif -->
                                                </block>
                                            </block> 
                                       </block>
                                       
                               </view>
                            </view> 
                        </block>
                   </view>                   
                   <view class="info_title" v-if="activeManjian || activeDiscount">优惠</view>
                   <view class="info_text">
                        <view class="info_line" v-if="activeManjian != ''">
                           <view class='cut_icon'>减</view>
                           <text>{{activeManjian}} </text>
                       </view>
                       <view class="info_line" v-if="activeDiscount != ''">
                           <view class='cut_icon dis'>折</view>
                           <text>{{activeDiscount}} </text>
                       </view>
                   </view>
                   <view class="info_title">配送</view>
                   <view class="info_text">
                       <view class="info_line">
                           <text>起送￥{{storeInfo.start_send_price}}</text>
                           <view class="slide_text">|</view>
                           <text>配送￥{{storeInfo.send_price}}</text>
                       </view>
                      <!-- <view class="info_line">配送时间：08:00-23:00</view>    -->    
                   </view>
                   <view class="info_title">公告</view>
                   <view class="info_text">{{storeInfo.notice}}</view>
               </view>
            </view>
            <view class='close_together' @click="hideStoreDetail()"> </view>
        </view>
    </view>
    
</view>                                                                                          
</template>

<script>
    import Big       from '../../common/big.js';
    import uniFly    from 'unifly';
	import request   from '../../common/request.js';
    import md5       from '../../common/md5.js';
	import $api_base from '../../api/api_base.js';
	import topNav    from '@/template/topnav/index.vue';
    import goodsItem from '@/template/goods/index/index.vue';
    import shopCart  from '@/template/shopCart/index/index.vue';
    import event     from '../../common/event.js';
    var minPrice = 0;  //起送價格
    var carArray1 = [];
    var carTmp = [];
  //  var cypto = hex.default;
    var discountGoodsNum = 0;
    var orderNum = 0;
    var activeTimer = null;
    var groupArray = [];   //拼单菜单
    var storeId = '';
    var schoolId = 0;
    export default {
		components: { topNav,goodsItem,shopCart },
		data:function() {
			return {
                loadOver1: true,
                hideOver1: true,
                loadOver: false,
                hideOver: false,
				openId: '',
                storeId: '',
                showStoreInfo: false,
                activeTime: ['00', '00', '00'],
                activeStatusText: '暂无班次',
                activeNumText: '',
                personList: [],
                arrAll:[],
                showGroupRule: false,
                tabbarId: 1,
                categoryIndex: 0,
                categoryInfo: '', //当前选中分类信息
                categoryList: [],
                goodsList: [],
                storeInfo: {},
                currentInfo:'',
                activeList: [],
                group_info: [],
                groupList: [],    //拼单详情信息
                toView: 'order0',
                toItem: '',
                scrollTop: 0,
                foodCounts: 0,
                totalPrice: 0,// 总价格
                totalCount: 0, // 总商品数
                carArray: [],
                carList: [],
                payDesc: '',
                deliveryPrice: 0,
                fold: true,
                selectFoods: [{price: 20, count: 2}],
                cartShow: 'none',
                status: 0,
                storeHeight: 500, //商品滚动高度,
                setting: {
                    show: false,
                    item: [],
                    price: 0,
                    showPrice: 0
                },
                sid: '',  //来源
                header: '',     
                aid: 0,   //相关来源id
                animate: false,
                navH: 0,
                n:0,
                scene:'',
                shareUid: '',
                finishTime: '',
                goodsDetail: {
                    show: false,
                    index: 0,
                    src: '',
                    title: '',
                    info: '',
                    num: '',
                    price: ''
                },
                showBuyTogether: false,
                group_id: 0,
                group_status: 0,   //拼单状态
                is_master: false,  //是否为发起人
                master_id: '',     //发起人id
                goodsAdd: {},
                goodsKeySub:'',
                goodsKeyAd:'',
                self_money:0,
                totalPrice_all:0,     //拼单总价
                totalCount_all: 0,    ////拼单总数
                showCheckGroup:false,
                stillCheckList:[],
                toPay: true,
                diffPrice: 0,
                showGetUser_1: false,
                showGetUser_2: false,
                nickName:'同学快跑',
                face:'',
                firstIn: true,
                navigationClose: false,
                groupOpen: false,
                systemInfo:'',
                ok:'',
                bang:false,
                lock: false,
                lockTime: 0,
                onLoadIn:false,
                showDisable: false,
                isOut: false,
                showGetUserStorage: '0',
                windowHeight:0,
                statusBarHeight: 0,
                n:0,
                must: false,
                packageFee:0,
                mustCid: 0,
                mustClistKey:0,
                mustSum:0,      //必选品总量
                activeManjian: '',
                activeDiscount: '',
                packetList:[],
                categoryId: '',
                goodsId: '',
                s_type:1,
                is_content:1,
                eval_list:[],
                score:0,
                pack:0,
                packInt:0,
                packFloat:0,
                taste:0,
                tasteInt:0,
                tasteFloat:0,
                on_time:0,
                eva_count:0,
                eva_good_count:0,
                eva_middle_count:0,
				eva_image_count:0,
                eva_bad_count:0,
                evalPage:0,
                evalLimit:30,
                noMore:false,
                storeTop:0,
                isRegisted: false,
                bindPhone: 0,
                listServiceType: 0,
                select_index_ca:0,
                select_index: 0,
                right_height: [], //右侧每个内容的高度集合
                right_scroll: 0, //右侧的滑动值
                left_height: 0, //左侧总高度
                left_scroll: 0, //左侧滑动值
                last: 0,
                timeout: null,
                is_super: 0,          //1为超市
                showScrollbar: false,
                fromPage: ''
			}
		},
        onLoad:function(options){
            console.log(options);
            uni.removeStorageSync('STOREDATA');
            uni.removeStorageSync('SEARCHDATA');
            var self        = this;
            var finishTime  = options.finishTime || '';
            var sid         = options.sid || 'index';
            var adId        = options.adId || 0;
            var header      = options.header || '';
            var master_id   = options.masterId || '';
            self.categoryId = options.categoryId || '';
            self.goodsId    = options.id || '';
            var storeId     = '';
            var showGetUserStorage = uni.getStorageSync('showGetUserStorage') || '0';
            discountGoodsNum = 0;
            getApp().globalData.listServiceType = options.serviceT || '';
            getApp().globalData.schoolId = options.schoolId || getApp().globalData.schoolId;
            if (sid === 'qrcode') {
                let q = decodeURIComponent(options.q);
                carArray1 = [];
                if (q) {
                    storeId = event.getQueryString(q, 'storeId');
                }
            }else{
                storeId = options.storeId || 415;
            }
            // #ifdef MP-ALIPAY
                if(getApp().globalData.qrCode != ''){ 
                    let qr  = getApp().globalData.qrCode;
                    var qq = qr.indexOf('?');
                    if (qq > 0) {
                        // 存在参数
                        var qOption  = qr.substring(qq + 1, qr.length); //获取所有的参数
                        var qList    = qOption.split('&');
                        var string   = {};
                        for (let i in qList) {
                            let qList_v = qList[i].split('=');
                            string[qList_v[0]] = qList_v[1];
                        }
                        storeId = string.storeId || '58';
                        sid  =  string.sid  || 'qrcode';
                    }
                }
            // #endif
            schoolId = getApp().globalData.schoolId;
            if(getApp().globalData.userInfo){
                self.bindPhone = getApp().globalData.userInfo.bind_phone || 0
            }else{
                self.bindPhone = 0;
            }
            self.categoryIndex = 0;
            self.fromPage   = '';
            self.isRegisted = getApp().globalData.isRegisted;
            self.isOut      = false;
            self.sid        = sid;
            self.aid        = adId; 
            self.finishTime = finishTime;
            self.master_id  = master_id;
            self.header     = header;
            self.storeId    = storeId;
            self.navH       = getApp().globalData.navHeight;
            self.n          = getApp().globalData.n;
            self.bang       = getApp().globalData.bang;
            self.onLoadIn   = true;
            self.showGetUserStorage = showGetUserStorage;
            self.listServiceType = getApp().globalData.listServiceType;
            carArray1       = [];
            $api_base.post_new($api_base.groupOpen,{},1).then(function(res) {
                let data = res.data;
                if (data.ok == 1) {
                    self.groupOpen = true;
                }else{
                    self.groupOpen = false;
                }
            })
       //     if (!uni.getStorageSync('openid')) {  //新用户
            if(self.sid != 'index' && self.sid != 'oneself' && self.sid != 'group'){        //不是从列表进入
               	self.initApp(storeId);
            }else{
                if (self.sid == 'buy_together') {  //拼单分享进入
                    self.getGroupId();
                }else {
                    self.loadStart();
                }
            }
        },
        onShow:function() {
            var self = this;
            if(uni.getStorageSync("SEARCHDATA")){
                let searchData = uni.getStorageSync("SEARCHDATA"); 
                carArray1 = event.arrToObj(searchData.carArray1);
            }
            if(self.fromPage != 'storeSearch'){
                setTimeout(function(){
                    self.setHeight();
                },400)
            }
            
            if(self.groupOpen){
                $api_base.post_new($api_base.changeStatus,{ wxapp_id: self.openId, group_id: self.group_id, status: 1 },1).then(function(res) {
                    if (res.data.ok == 1) { }
                    self.setHeight();
                });
            }
            if( self.storeInfo){
                if (self.header == 'buy_together' && self.groupOpen) {
                    self.getGroupInfo();
                } 
                this.payDesc = this.payDescFunc();
            }
            self.isRegisted = getApp().globalData.isRegisted;
        },
        methods:{
            setHeight: function () {
                var self = this;
                uni.getSystemInfo({
                    success(res) {
                        var statusBarHeight = self.statusBarHeight;
                        var navH = getApp().globalData.navHeight;
                        self.systemInfo = res.system;
                        self.windowHeight = res.windowHeight; 
                        self.statusBarHeight = res.statusBarHeight; 
                        self.navH = navH;
                        self.n = getApp().globalData.n;
                        var windowHeight = self.windowHeight;
                        uni.createSelectorQuery().select('.header').boundingClientRect(function (rect) {
                            uni.createSelectorQuery().select('.menu').boundingClientRect(function (menu) {
                                uni.createSelectorQuery().select('.reser_top_out').boundingClientRect(function (reser) {
                                    uni.createSelectorQuery().select('.red_packet_content').boundingClientRect(function(red){     
                                       // #ifdef MP-ALIPAY
                                        self.storeTop = rect.height + menu.height + reser.height +red.height;  
                                        self.storeHeight = windowHeight - rect.height - menu.height - reser.height -red.height - statusBarHeight - 30;
                                        // #endif
                                        // #ifdef MP-WEIXIN
                                        if(reser.height>0){
                                            self.storeHeight = windowHeight - rect.height - menu.height - reser.height -red.height - 90;
                                            self.storeTop = rect.height + menu.height + reser.height +red.height + 50; 
                                        }else{
                                            self.storeHeight = windowHeight - rect.height - menu.height -red.height - statusBarHeight - 90;
                                            self.storeTop = rect.height + menu.height +red.height + statusBarHeight + 50; 
                                        }   
                                        // #endif 
                                        if(self.is_super == 0){
                                            setTimeout(function() {
                                                 self.getHeightList();
                                            }, 1000);
                                        }
                                        setTimeout(function(){ self.loadOver1 = false; },1100);
                                        setTimeout(function(){ self.hideOver1 = false; },1200); 
                                        
                                    }).exec();
                                }).exec();
                            }).exec();
                        }).exec();
                    }
                });
                
            },
            initApp: function (storeId) {
                var self = this;
                self.loginReg().then(function () {
                    $api_base.post($api_base.homeIndex,{ long_lat: getApp().longLat, school_id:schoolId },1).then(function(res) {
                        let data = res.data;
                        if (data.ok == 2) {
                            getApp().globalData.schoolInfo = data.schoolInfo;
                            getApp().globalData.userInfo = data.userInfo;
                            getApp().globalData.schoolList = data.schoolList;
                            getApp().kfPhone = data.kfPhone;
                            getApp().isLogin = true;
                            self.loadStore(storeId);
                            uni.setStorageSync('uid', data.userInfo.uid);
                            self.showGetUser_1 = true;
                            if(data.userInfo.bind_phone == 0){
                                self.isRegisted = false; 
                            }else{
                                self.isRegisted = true; 
                            }
                        } else if (data.ok == 1){
                            getApp().globalData.schoolInfo = data.schoolInfo;
                            getApp().globalData.userInfo = data.userInfo;
                            getApp().globalData.schoolList = data.schoolList;
                            getApp().kfPhone = data.kfPhone;
                            getApp().isLogin = true;
                            self.loadStore(storeId);
                            uni.setStorageSync('uid', data.userInfo.uid);
                            if(data.userInfo.bind_phone == 0){
                                self.isRegisted = false; 
                            }else{
                                self.isRegisted = true;
                            }
                        }
                    });  
                });
            },
			 // 点击图片查看
			imgMap:function (index,url){
			    uni.previewImage({
					 current:index,
			         urls:url.currentTarget.dataset.id, //这里一定是数组，不然就报错
			        })
			},
            beforeInitData: function () {
                var date = new Date();
                var self = this;
                if (self.lock) return false;
                self.lock = true;
                $api_base.post_new($api_base.groupOpen,{},1).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        self.groupOpen = true;
                    } else {
                        self.groupOpen = false;
                    }
                })
                var storeId = self.storeId;
                if (!uni.getStorageSync('openid'))
                  self.initApp(storeId);
                else {
                    if (self.sid == 'buy_together') {  //拼单分享进入
                        self.getGroupId();
                    } else {
                        self.loadStart();
                    }
                }
            },
            getGroupId:function(){
                var self = this;
                var storeId = self.storeId;
                var master_id = self.master_id;
                $api_base.post_new($api_base.getGroupId,{ store_id: storeId, master_uid: master_id }).then(function (res) {
                    let data = res.data;
                    if (data.code == 1) {
                        self.group_id = data.data.group_id;
                        self.loadStart();
                    }
                })
            },
            loadStart: function (){
                var self       = this;
                self.scene     = getApp().globalData.scene;
                self.openId    = uni.getStorageSync('openid');  
                var storeId    = self.storeId;
                var finishTime = self.finishTime;
                var sid        = self.sid;
                var adId       = self.aid;
                var header     = self.header;
                var group_id   = self.group_id;
                if (sid === 'order_list' || sid === 'order_detail' || sid === 'index' || sid === 'oneself' || sid === 'ad' || sid === 'group') {
                    carArray1 = [];
                    minPrice = 0;
                    carTmp = [];
                    discountGoodsNum = 0;
                    orderNum = 0;
                }
//                 if (sid === 'ad') {
//                     app.HttpService.ad({ ad_id: adId }).then(function (data) {
// 
//                     });
//                 }

                if (sid === 'share' || sid === 'qrcode' || sid === 'share_group' || sid === 'buy_together') {
                    carArray1 = [];
                    self.loadStore(storeId);            
                } else {
                    self.loadStore(storeId);
                }
                //库存不足刷新
                event.on('selOutReload', this, function (e) {
                    var index = self.categoryIndex || 0;
                    var goods = self.goodsList || [];
                    var categoryInfo = self.categoryList[index];
                    var list = [];
                    var key = e.key;
                    if (key === '' || carArray1[key] === undefined) return false;
                    for (var n = carArray1[key].num - e.num; n > 0; n--) {
                        for (var k in carTmp) {
                            if (carTmp[k].key === key) {
                                carTmp.splice(k, 1);
                                break;
                            }
                        }
                    }
                    var buyNum = carArray1[key].num;
                    carArray1[key].num = e.num;
                    if (carArray1[key].num === 0) {
                        var numDiscount = carArray1[key].goods.discount.num_discount || 0;
                        var openDiscount = carArray1[key].goods.open_discount || 0;
                        if (numDiscount > 0 && openDiscount > 0 && carArray1[key].discountNum > 0) {
                            discountGoodsNum -= carArray1[key].discountNum;
                        }
                        delete carArray1[key];
                    } else {
                        for (var i = buyNum - e.num; i > 0; i--) {
                            self.callCarSubPrice(key);
                        }
                    }
                    self.callCarList();
                    self.goodsList = goods;
                    self.carTmp = carTmp;
                    self.calTotalPrice();
                    self.payDesc = self.payDescFunc();
                    var carList = self.carList;
                    var must = false;
                    $api_base.post($api_base.goodsListV5,{ store_id: this.storeId, cid: categoryInfo.cid, group_id: self.group_id}).then(function(res) {
                        let data = res.data;
                        if (data.ok == 1) {
                            self.is_super = data.is_super;
                            if (data.goods_list.length > 0) {
                                data.goods_list.map(function (i) {
                                    for (var K in carList) {
                                        if (carList[K].id == i.id) {
                                            if (carList[K].stdClass.spec !== undefined) {
                                                i.sel_out = 1;
                                                i.spec.map(function (n, m) {
                                                    if (n.id == carList[K].stdClass.spec.id) {
                                                        i.Count = carList[K].num;
                                                        i.spec[m].num = i.spec[m].num - carList[K].num;
                                                    }
                                                    if (i.spec[m].num > 0) i.sel_out = 0;
                                                });
                                            } else {
                                                i.sel_out = 1;
                                                i.Count = carList[K].num;
                                                i.num = i.num - carList[K].num;
                                                if (i.num > 0) i.sel_out = 0;
                                            }
                                        }
                                    }
                                    list.push(i);
                                })
                            }
                            must = data.must_choose_list_num && data.must_choose_list_num > 0 ? true : false;
                            self.categoryInfo  = categoryInfo;
                            self.categoryIndex = index;
                            self.goodsList     = list;
                            self.toView        = 'order' + index.toString();
                            self.group_id      = data.group_id;
                            self.must          = must;
                        }else{

                        }
                    });
                });
            },
            loadStore: function (storeId) {
                var self = this;
                var sid = self.sid;
                var animate = self.animate;
                var is_master = false;
                var must = false;
                var mustSum = 0;
                $api_base.post($api_base.goodsListV5,{ store_id: storeId, sid: sid, group_id: self.group_id },1).then(function(res) {
                    let data = res.data;
                    // self.loadOver      = true;
                    // self.hideOver      = true;
                    if (data.ok == 1) {
                        self.is_super = data.is_super;
                        if(data.store_info.use_red_packet==0)
                            self.loadPacket();
                            
                        var categoryList = data.category_list;
                        for(let i in categoryList){
                            if(!categoryList[i].count)
                                categoryList[i].count = 0;
                        }
                        var storeInfo = data.store_info || {};
                        let arrAll = [];
                        data.active_list.forEach(function (t) {
                              let arr = [];
                              arr = t.text.split(';');
                              arr.forEach((item) => {
                                  arrAll.push(item);
                              });
                          })
                          let source3 = { arrAll: arrAll };
                          Object.assign(data, source3);

                        if (storeInfo.open_group_active > 0 && self.sid != "share_group") {  //开车店铺
                            self.sid = 'group';
                        }
                        sid = self.sid;
                        if (sid === "group" || sid === 'share_group' || sid==="index") {  //    搜索进开车店铺
                            var currentInfo = data.current_class_info || null;
                            self.currentInfo = currentInfo;
                            if(data.current_class_info)
                               self.currentInfo.current_finishTime = event.timestampToTime(currentInfo.current_finishTime) || '';
                            self.joinRoom(); 
                            self.loadGroupData(currentInfo);
                        }  
                        minPrice = data.store_info.start_send_price;
                        must = data.must_choose_list_num && data.must_choose_list_num > 0 ? true : false;
                        getApp().globalData.schoolId = data.store_info.school_id || 0;
                        schoolId = data.store_info.school_id;
                        self.storeId       = storeId; 
                        self.storeInfo     = storeInfo; 
                        self.arrAll        = arrAll;
                        self.activeList    = data.active_list;
                        self.categoryList  = categoryList; 
                        self.categoryInfo  = categoryList.length > 0 ? categoryList[0] : [];
                        self.deliveryPrice = data.store_info.send_price; 
                        self.group_id      = data.group_id;
                        self.must          = must;
                        self.mustCid       = data.must_cid;
                        self.mustClistKey  = data.must_clist_key;
                        self.mustSum       = data.must_choose_list_num ;
                        self.goodsList     = data.goods_list;

                        if(data.store_info.open_oneself == 2){   //仅自取
                            self.listServiceType = 2;
                            getApp().globalData.listServiceType = 2;
                        }else if(data.store_info.open_oneself == 0){   //仅外卖
                            self.listServiceType = 0;
                            getApp().globalData.listServiceType = 0;
                        }
                        getApp().globalData.schoolList = data.schoolList || [];
                        uni.setNavigationBarTitle({
                            title: data.store_info.shop_name
                        }) 
                        if(self.sid != "buy_together")
                            self.payDesc = self.payDescFunc();
                        self.addAnimate();
                        if (data.group_id != 0 && data.group_id) {
                            getApp().carData = {
                                storeId: storeId,
                                storeInfo: storeInfo,
                                carList: [],
                                groupList: []
                            };
                            if (data.master_id == self.openId) {
                                is_master = true;
                                if(data.msg == '拼单已提交或者已经取消'){
                                    self.group_status = data.group_status;
                                    self.showDisableModal();
                                    return false
                                }
                            } else {
                                is_master = false;
                                if(data.group_status != 1){
                                    self.group_status = data.group_status;
                                    self.showDisableModal();
                                    return false
                                }
                            }
                            self.group_info = data.group_info;
                            self.header     = 'buy_together';
                            self.group_id   = data.group_id;
                            self.is_master  = is_master;
                            self.master_id  = data.master_id;
                            self.getGroupInfo();
                        }
                        getApp().globalData.qrCode = '';
                    } else if (data.ok == -1){
                        self.initApp(storeId);
                    }
                    self.setHeight();
                    
                    if(self.categoryId != '' && self.goodsId !=''){
                        if(self.is_super == 1){
                            const index = categoryList.findIndex(item => item.cid === self.categoryId);
                            var l = {
                                currentTarget: {
                                    dataset: {
                                        itemIndex: index
                                    },
                                    id: self.categoryId,
                                }
                            };
                            self.selectMenu(l,1,true);
                        }else{
                            self.toItem = 'item_'+self.goodsId;
                            let index = categoryList.findIndex(item => item.cid === self.categoryId);
                            let index2 = self.goodsList[index].findIndex(item => item.id == self.goodsId);
                            self.select_index = index;
                            self.select_index_ca = index;
                            var l = {
                                currentTarget: {
                                    dataset: {
                                        link: index,
                                        index: index2
                                    },
                                }
                            };
                            setTimeout(function() {
                                self.addCart(l);
                            }, 100);
                        }
                    }  
                });
            },
            loadPacket: function(){
                var self = this;
                var u_id = uni.getStorageSync('openid');
                var s_id = self.storeId;
                $api_base.post($api_base.storeRedpacketList,{ s_id: s_id,u_id: u_id },1).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        self.packetList = data.data;
                       // if(self.packetList.length>0)
                            self.setHeight();
                    }
                })
            },
            
            getPhoneNumber: function(e){
                var self = this;
                if (e.detail.errMsg == 'getPhoneNumber:ok') {
                    $api_base.post($api_base.getDecryptData,{encryptedData: e.detail.encryptedData, iv: e.detail.iv,school_id: schoolId}).then(function (e) {
                        let data = e.data;
                        if(data.ok == 0){
                            self.isRegisted = false;
                            getApp().globalData.isRegisted = self.isRegisted;
                            uni.showModal({
                             	title: '',
                             	content: '注册失败.',
                             	showCancel: false,
                             	confirmText: '知道了',
                             	confirmColor: '#00B89D',
                             	success(res) {
                             		if (res.confirm) {
                             			console.log('用户点击确定')
                             		} else if (res.cancel) {
                             			console.log('用户点击取消')
                             		}
                             	}
                            })
                        }else{ 
                            self.isRegisted  = true;
                            self.bindPhone  = 1;
                            getApp().globalData.userInfo.bind_phone = 1;
                            getApp().globalData.isRegisted = self.isRegisted;
                            uni.showToast({
                                title:'注册成功'
                            })
                            self.loadNewPacket()
                        }
                    })
                }else{
                    uni.navigateTo({
                        url:'/pages/index/bind-phone/index?from=goods'
                    })
                    //self.showLoginoutTip = true;
                    getApp().globalData.isRegisted = self.isRegisted;
                }
            },
            onGetAuthorize: function(res){
                var self = this;
                my.getPhoneNumber({
                    success: (res) => {
                        let encryptedData = res.response;
                        $api_base.post($api_base.getAliDecryptData,{response: res.response, school_id: schoolId}).then(function (e) {
                            let data = e.data;
                            if(data.ok == 0){    
                                self.isRegisted = false;
                                uni.showModal({
                                 	title: '',
                                 	content: '注册失败.',
                                 	showCancel: false,
                                 	confirmText: '知道了',
                                 	confirmColor: '#00B89D',
                                 	success(res) {
                                 		if (res.confirm) {
                                 			console.log('用户点击确定')
                                 		} else if (res.cancel) {
                                 			console.log('用户点击取消')
                                 		}
                                 	}
                                })
                            }else{ 
                                self.isRegisted = true;
                                self.bindPhone = 1;
                                getApp().globalData.userInfo.bind_phone = 1;
                                uni.showToast({
                                    title:'注册成功,可领取红包'
                                })
                                self.loadNewPacket();
                            }
                        })
                    },
                    fail: (res) => {
                        console.log('getPhoneNumber_fail');
                    },
                });
            },
            onAuthError(e) {  
                uni.navigateTo({
                    url:'/pages/index/bind-phone/index?from=goods'
                }) 
                getApp().globalData.isRegisted = self.isRegisted;
            },
            loadNewPacket: function(n){
                var self = this;
                self.firstShow = false;
                var u_id = uni.getStorageSync('openid');
                var school_id = getApp().globalData.schoolId;
                $api_base.post($api_base.getRedpackeNew,{u_id:u_id,r_type:2,school_id:school_id},1).then(function(res) {
                	var data = res.data;
                    if(data.ok==1){
                        if(n) self.getPacket(n)
                    }
                })
            },
            getPacket: function(id){
                var self = this;
                var u_id = uni.getStorageSync('openid');
                $api_base.post($api_base.getStoreRedpacket,{ red_id: id,u_id: u_id },1).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        uni.showToast({title: '领取成功', icon: "none"});
                        self.loadPacket();
                    }else{
                        uni.showToast({title: data.msg, icon: "none"});
                        
                    }
                })
            },
            addAnimate: function(){
                var self = this;
                var animate  = this.animate
                self.animate = !animate
                setTimeout(function () {
                    self.addAnimate()
                }, 10000)
            },
            joinRoom: function () {
                event.on('socketLoginSuccess', this, function () {
                    var data = {cmd: "joinRoom", storeId: this.storeId, auth: Config.PUB_KEY};
                    uni.sendSocketMessage({data: JSON.stringify(data)});
                });
                //event.on('groupReload', this, function () {
                    this.groupReload();
               // });
                getApp().$vm.$options.methods.openSocket();
            },
            groupReload: function () {
                var self = this;
                $api_base.post($api_base.getGroupInfo,{ store_id: self.storeId },1).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        var currentInfo = data.current_class_info || null;
                       // self.currentInfo = currentInfo;
                        self.currentInfo = currentInfo;
                       if(data.current_class_info)
                           self.currentInfo.current_finishTime = event.timestampToTime(currentInfo.current_finishTime) || '';
                        self.loadGroupData(currentInfo);
                    }
                });
            },
            loadGroupData: function (currentInfo) {
                var self = this;
                if (currentInfo && currentInfo.is_open > 0) {
                    var psersionNum = currentInfo.person_num || 0;
                    var residueTime = currentInfo.residue_time || 0;
                    var personList = [];  //参与人数
                    var activeStatusText = currentInfo.status_text || '';
                    var activeNumText = currentInfo.num_text || '';
                    if (psersionNum > 0) {
                        for (var i = 0; i < 3; i++) {
                            if (psersionNum > 0) personList.push(1);
                            else personList.push(2);
                            psersionNum--;
                        }
                    }
                    if (residueTime > 0) self.activeTimeEvent(residueTime);
                    self.openGroupActive  = true;
                    self.activeStatusText = activeStatusText;
                    self.activeNumText    = activeNumText;
                    self.personList       = personList;
                } else {
                    self.openGroupActive  = false;
                    self.activeStatusText = '...暂无班次';
                    self.activeNumText    = '等待活动开启';
                    self.personList       = [];
                }
                self.setHeight();
            },
            activeTimeEvent: function (s) {
                var self = this;
                if (s <= 0) {
                    this.activeTime = ['00', '00', '00'];
                    clearTimeout(activeTimer);
                    self.groupReload();
                    return false;
                }
                var h = new Big(s / 3600).round(0, 0).toString();
                //var m = new Big(s % 3600 / 60).round().toString();
                var m = parseInt(s % 3600 / 60);
                var t = new Big(s % 60).round(0).toString();
                if (parseInt(h) < 10) h = '0' + h;
                if (parseInt(m) < 10) m = '0' + m;
                if (parseInt(t) < 10) t = '0' + t;
                this.activeTime = [h, m, t];
                activeTimer = setTimeout(function () {
                    self.activeTimeEvent(--s);
                }, 1000);
            }, 
            getGroupInfo: function () {
                var self = this;
                let list = [];
                let totalCount_all = 0;
                let cartShow    = self.cartShow;
                let minPrice    = self.storeInfo.start_send_price;
                let is_master   = self.is_master;
                let sid         = self.sid;
                let packageFee  = 0;
                let must        = false;
                let mustSum     = self.mustSum;
                let mustCid     = self.mustCid;
                self.openId     = uni.getStorageSync('openid');
                $api_base.post_new($api_base.groupInfo,{ wxapp_id: uni.getStorageSync('openid'), group_id: self.group_id },1).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {               
                        groupArray = data.data || [];
                        for(let i in groupArray){
                            for (let j in groupArray[i].goods_list){
                                totalCount_all += groupArray[i].goods_list[j].num;
                            }
                        }
                        var orderList = data.order_list || [];
                        let l = orderList.length;
                        if (mustCid != 0) {
                          if (l > 0) {
                            const index = orderList.findIndex(orderList => orderList.category_id == mustCid);
                            if (index>=0) {
                              must = false;
                            } else {
                              must = true;
                            }
                          } else {
                            must = true;
                          }
                        }
                        if (totalCount_all == 0){
                            cartShow = 'none';
                        }else{
                            packageFee = data.food_box_money + data.package_bag_money;
                            packageFee = new Big(packageFee).round(2).toString();
                        }
                        var total_money = data.total_money || 0;
                        var diff = minPrice - total_money;
                        diff = new Big(diff).round(2).toString();
                        var totalPrice = new Big(total_money).round(2).toString();
                        self.must = must;
                        self.cartShow = cartShow;
                        self.group_status = data.group_status;
                        if (data.master_id == self.openId) {
                            is_master = true;
                        } else {
                            is_master = false;
                        }
                        if ((!is_master) && data.group_status == 2) {
                             if (sid === 'buy_together') {
                                var header = 'buy_together';
                                var sid = "buy_together";
                                getApp().carData = {
                                     storeId: self.storeId,
                                     storeInfo: self.storeInfo,
                                     carList: [],
                                     groupList: []
                                };
                                getApp().globalData.isRegisted = self.isRegisted;
                                uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + sid + '&aid=' + self.aid + '&header=' + header + '&groupId=' + self.group_id + '&is_master=' + is_master + '&listServiceType=' + getApp().globalData.listServiceType });
                            } else {
                                self.showDisableModal();
                                return false
                            }
                        }
                        self.groupList      = data.data || [];
                        self.totalCount_all = totalCount_all;
                        self.totalPrice_all = parseFloat(totalPrice);
                        self.self_money     = data.self_money || 0;
                        self.diffPrice      = diff;
                        self.packageFee     = packageFee;
                        self.newGoodsList();  
                    } 
                }); 
            },
            showDisableModal: function(){
                var self = this;
                var text = '';
                var sid = self.sid;
                var aid = self.aid;
                var header = self.header;
                var group_id = self.group_id;
                var is_master = self.is_master;
                if(self.group_status == 2){
                    text = '好友已经提交了订单，您已经无法继续选购商品';
                }else if (self.group_status == 3) {
                    text = '拼单已取消，前往自行下单';
                }else if (self.group_status == 4 || self.group_id == 0) {
                    text = '拼单已完成，前往自行下单';
                } else if (self.group_status == 5) {
                    text = '拼单失败，前往自行下单';
                }
				if(text!=''){
					uni.showModal({
					    title: '',
					    content: text + '',
					    showCancel: false,
					    confirmText: '知道了',
					    confirmColor: '#00B89D',
					    success(res) {
					        if (res.confirm) {
					            let tmpCar = [];
					            if (self.group_status == 2 && !is_master){
					                getApp().globalData.isRegisted = self.isRegisted;
					                uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + sid + '&aid=' + aid + '&header=buy_together&groupId=' + group_id + '&is_master=false' + '&listServiceType=' + getApp().globalData.listServiceType });
					                return false
					            }else if (self.group_status == 3 || self.group_status == 4 || self.group_status == 5){
					                carArray1       = [];
					                self.header     = ' ';
					                self.sid        = 'buy_together';
					                self.firstIn    = false;
					                self.group_id   = 0;
					                self.groupList  = [];
					                self.totalCount = 0;
					                self.totalPrice = 0;
					                self.setHeight();
					                self.newGoodsList();
					            }
					            self.carList = tmpCar;
					            return false
					        } 
					    }
					})
				}
                return false
            },
            showByPerson: function () {
                var personList = this.personList || [];

                if (personList.length > 0) {
                    getApp().globalData.isRegisted = self.isRegisted;
                    uni.navigateTo({url: '/pagesGoods/goods/group-buy-person/index?storeId=' + this.storeId});
                }
            }, 
            selectMenu: function (e,n, mask,from_func) {
                var index        = e.currentTarget.dataset.itemIndex;
                var reload       = e.currentTarget.dataset.reload || false;
                var categoryInfo = this.categoryList[index];
                var carList      = this.carList;
                var self         = this;
                var list         = [];
                var mustSum      = self.mustSum;
                if (categoryInfo.cid == this.categoryInfo.cid && categoryInfo.tid <= 0 && !reload) {
                    if (categoryInfo.cid == this.categoryInfo.cid){  //当前菜单栏
                        if (n && n == 1) { 
                            self.addCart(l);
                        }
                    }
                    return false;
                }
                $api_base.post($api_base.goodsListV5,{
                    store_id: self.storeId,
                    cid: categoryInfo.cid,
                    tid: categoryInfo.tid,
                    group_id: self.group_id
                }).then(function (res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        if (data.goods_list.length > 0) {
                            data.goods_list.map(function (i, k) {
                                for (var K in carList) {
                                    if (carList[K].id == i.id) {
                                        if (carList[K].stdClass.spec !== undefined) {
                                            i.sel_out = 1;
                                            i.spec.map(function (n, m) {
                                                if (n.id == carList[K].stdClass.spec.id) {
                                                    i.Count += carList[K].num;
                                                    i.spec[m].num = i.spec[m].num - carList[K].num;
                                                }
                                                if (i.spec[m].num > 0) i.sel_out = 0;
                                            });
                                        } else {
                                            i.sel_out = 1;
                                            i.Count = carList[K].num;
                                            i.num = i.num - carList[K].num;
                                            if (i.num > 0) i.sel_out = 0;
                                        }
                                    }
                                }
                                list.push(i);
                            });
                        }
                        self.categoryInfo  = categoryInfo;
                        self.categoryIndex = index;
                        self.goodsList     = list;
                        self.toView        = 'order' + index.toString();
                        if(self.categoryId != '' && self.goodsId !=''){   
                            self.$nextTick(function(){
                                self.toItem = 'item_'+self.goodsId;
                            })
                        }
                        self.scrollTop = 0.1;
                        self.$nextTick(function(){
                            self.scrollTop = 0;
                        })
                        if (n && n == 1) {
                          if (mustSum == 1 && from_func == 'must') {    //如果只有一个必选品，自动展开或自动添加
                            let id = list[0].category_id;
                            var l = {
                              currentTarget: {
                                dataset: {
                                  id: id,
                                  index: '0'
                                }
                              }
                            }
                            self.addCart(l);
                          }else{
                              const index = self.goodsList.findIndex(item => item.id === self.goodsId);
                              var l = {
                                  currentTarget: {
                                      dataset: {
                                          index: index,
                                          id: self.categoryId
                                      },
                                      
                                  }
                              };
                              self.addCart(l);
                          }
                        }
                    }
                });
            },
            getMust: function(){
                  var mustCid = this.mustCid;
                  var mustClistKey = this.mustClistKey;
                  var link = '';
                  for(let i in this.categoryList){
                      if(this.categoryList[i].cid == mustCid){
                          link = this.categoryList[i].name
                      }
                  }
                  var l = {
                      currentTarget: {
                          dataset: {
                              itemIndex: mustClistKey,
                              name: link
                          },
                          id: mustCid,
                      }
                  };
                  if(this.is_super == 0){
                      this.choose(l);
                  }else{
                      this.selectMenu(l,1,true,'must');
                  }
                  
            },
            buyTogetherShow: function () {
                if(this.navigationClose && this.header != 'buy_together') return
                this.showBuyTogether = true;
            },
            buyTogetherClose: function () {
                this.showBuyTogether = false;
            },
            cancelBuyTogether: function(e){
                var self = this;
                var dataid = e;
                var group_id = self.group_id;
                var is_master = self.is_master;
                var group_status = self.group_status;
                var title = '';
                if (dataid == 'cancel') {
                    title = '取消';
                    uni.showModal({
                        title: '确定' + title + '吗？',
                        content: title + '后不会保留此次拼单内容',
                        cancelText: '继续拼单',
                        confirmText: title + '拼单',
                        confirmColor: '#00B89D',
                        success(res) {
                            if (res.confirm) {
                                $api_base.post_new($api_base.cancelGroup,{ wxapp_id: self.openId, group_id: group_id }).then(function (res) {
                                    let data = res.data;
                                    if (data.ok == 1) {
                                        var car_list = [];
                                        var totalCount = 0;
                                        for (let i in self.groupList) {
                                            if (self.openId == self.groupList[i].wxapp_id) {
                                                car_list = self.groupList[i].goods_list;
                                            }
                                        }
                                        var tmpcar = [];
                                        carArray1 = [];
                                        self.header = ''; 
                                        self.navigationClose = false; 
                                        self.group_id = 0; 
                                        self.groupList = []; 
                                        self.carList = tmpcar; 
                                        self.totalCount = 0; 
                                        self.totalPrice = 0;
                                        self.newGoodsList();
                                        
                                    } else {
                                        uni.showToast({ title: '取消拼单失败，请重试。', icon: 'none', duration: 2000 });
                                        return false;
                                    }
                                });
                            } else if (res.cancel) {
                                console.log('用户点击继续拼单')
                            }
                        }
                    }) 
                } else if (dataid == 'out') {
                    title = '退出';
                    $api_base.post_new($api_base.groupInfo,{ wxapp_id: self.openId, group_id: group_id }).then(function (res) {
                        let data= res.data;
                        if (data.ok == 1) {
                            if (data.group_status == 2) {
                                uni.showToast({ title: '发起人已提交了订单，您不能退出拼单.', icon: 'none', duration: 2000 });
                                return false;
                            } else if (data.group_status > 2) {
                                self.showDisableModal();
                                return false
                            }else if(data.group_status == 1){
                                uni.showModal({
                                    title: '确定' + title + '吗？',
                                    content: title + '后不会保留此次拼单内容',
                                    cancelText: '继续拼单',
                                    confirmText: title + '拼单',
                                    confirmColor: '#00B89D',
                                    success(res) {
                                        if (res.confirm) {
                                            $api_base.post_new($api_base.outGroup,{ wxapp_id: self.openId, group_id: group_id }).then(function (res) {
                                                let data = res.data;
                                                if (data.ok == 1) {
                                                    var tmpcar           = [];
                                                    carArray1            = [];
                                                    self.header          = ''; 
                                                    self.navigationClose = false; 
                                                    self.group_id        = 0; 
                                                    self.groupList       = [];
                                                    self.carList         = tmpcar; 
                                                    self.totalCount      = 0; 
                                                    self.totalPrice      = 0; 
                                                    self.isOut           = true;
                                                    self.newGoodsList();
                                                    self.setHeight();
                                                } else {
                                                    uni.showToast({ title: '退出拼单失败，请重试。', icon: 'none', duration: 2000 });
                                                    return false;
                                                }
                                            });
                                        } else if (res.cancel) {
                                            console.log('用户点击继续拼单')
                                        }
                                    }
                                }) 
                            }
                        }
                    })
                }
            },
            //刷新菜单列表
            newGoodsList: function(){
                var self = this;
                var sid             = this.sid;
                var storeId         = this.storeId;
                var categoryIndex   = this.categoryIndex;
                var is_master       = false;
                var categoryInfo    = this.categoryList[categoryIndex];
                var isOut           = this.isOut;
                $api_base.post($api_base.goodsList,{ store_id: self.storeId, cid: categoryInfo.cid, tid: categoryInfo.tid, sid: sid, group_id: self.group_id },1).then(function (res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        if (data.master_id == self.openId) {
                            is_master = true;
                        } else {
                            is_master = false;
                        }
                      //  self.storeInfo   = data.storeInfo;
                        self.goodsList    = data.goods_list || [];
                        self.group_info   = data.group_info || '';
                        self.group_status = data.group_status;
                        self.is_master    = is_master;
                       // self.payDesc      = self.payDescFunc();
                        if ((!is_master) && data.group_status > 1 && (!isOut)) {
                            self.showDisableModal();
                            return false
                        }
                        setTimeout(function(){self.setHeight();},200)
                        
                    }
                })
            },
            showDisableModal: function(){
                var self = this;
                var text = '';
                var sid = self.sid;
                var aid = self.aid;
                var header = self.header;
                var group_id = self.group_id;
                var is_master = self.is_master;
                if(self.group_status == 2){
                    text = '好友已经提交了订单，您已经无法继续选购商品';
                }else if (self.group_status == 3) {
                    text = '拼单已取消，前往自行下单';
                }else if (self.group_status == 4 || self.group_id == 0) {
                    text = '拼单已完成，前往自行下单';
                } else if (self.group_status == 5) {
                    text = '拼单失败，前往自行下单';
                }
                uni.showModal({
                    title: '',
                    content: text + '',
                    showCancel: false,
                    confirmText: '知道了',
                    confirmColor: '#00B89D',
                    success(res) {
                        if (res.confirm) {
                            let tmpCar = [];
                            if (self.group_status == 2 && !is_master){
                                getApp().globalData.isRegisted = self.isRegisted;
                                uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + sid + '&aid=' + aid + '&header=buy_together&groupId=' + group_id + '&is_master=false' + '&listServiceType=' + getApp().globalData.listServiceType });
                                return false
                            }else if (self.group_status == 3 || self.group_status == 4 || self.group_status == 5){
                                carArray1 = [];
                                self.header = ' '; 
                                self.sid = 'buy_together'; 
                                self.firstIn = false; 
                                self.group_id = 0; 
                                self.groupList= []; 
                                self.totalCount= 0; 
                                self.totalPrice=0;
                                self.setHeight();
                                self.newGoodsList();
                            }
                            self.carList = tmpCar;
                                return false
                        } 
                    }
                })
                return false
            },
            onShareAppMessage: function (e) {
                var self = this;
                var sid = self.sid;
                var dataid = '';
                if(e.from != "menu"){
                    dataid = e.target.dataset.id;
                }
                var shareImg = self.storeInfo.share_icon || '';
                var carList = self.carList;
                var header = '';
                var openId = uni.getStorageSync('openid');
                var finishTime = self.finishTime || '';
                var showGetUser_1 = self.showGetUser_1;
                var showGetUserStorage = self.showGetUserStorage;
                var serviceT = '';
                if (getApp().globalData.listServiceType == '') {
                  serviceT = sid == 'oneself' ? self.storeInfo.open_oneself : 0;
                } else {
                  serviceT = getApp().globalData.listServiceType
                }
                if (sid == "share_group" || sid == "group") {
                    sid = "share_group";
                } else {
                    sid = 'share';
                }   
                if ( dataid == "0" || dataid == '01' ) {  //拼单分享
                    sid = "buy_together";
                    header = "buy_together";
                    var tmpcar = [];
                    carList.map(function (i) {
                        tmpcar.push({
                            id              : i.id,
                            orderNum        : i.orderNum,
                            discountNum     : i.discountNum,
                            name            : i.goods.name,
                            stdClass        : i.stdClass,
                            key             : i.key,
                            num             : i.num,
                            desc            : i.desc,
                            showDesc        : i.showDesc,
                            box_id          : i.box_id,
                            food_box_money  : i.food_box_money,
                            category_id     : i.category_id
                        });
                    });
                    $api_base.post_new($api_base.createGroup,{ wxapp_id: openId, store_id: self.storeId }).then(function(res) {
                        let data = res.data;
                        if (data.ok == 1) {
                            var group_id = data.data.group_id;
                            self.header = header;
                            self.group_id = group_id;
                            self.is_master = true; 
                            self.carList = tmpcar;
                            self.showBuyTogether = false;
                            self.setHeight();
                            if (self.carList.length > 0) {
                                self.confirmGoods();
                            }
                        } else {
                            uni.showToast({ title: '分享失败，请重试。', icon: 'none', duration: 2000 });
                            return false;
                        }
                    });
                    return {
                        title: '邀你一起拼单【' + self.storeInfo.shop_name + '】',
                        path: '/pages/goods/goods?storeId=' + self.storeId + '&sid=' + sid + '&header=' + header + '&masterId=' + openId + '&schoolId=' + schoolId,
                        imageUrl: shareImg,
                        success: function (res) {
                        },
                        fail: function (res) {

                        }
                    }
                }else{
                    return {
                        title: this.storeInfo.shop_name,
                        path: '/pages/goods/goods?storeId=' + this.storeId + '&sid=' + sid + '&header=' + header + '&finishTime=' + finishTime + '&schoolId=' + schoolId + '&serviceT=' + serviceT,
                        imageUrl: shareImg,
                        success: function (res) {
                            // 转发成功
                        },
                        fail: function (res) {
                            // 转发失败
                        }
                    }
                }
            },
            //确定/修改拼单商品接口
            confirmGoods: function(){
                var self = this;
                var carList = self.carList;
                var car_list = JSON.stringify(carList);
                $api_base.post_new($api_base.confirmGoods,{ wxapp_id: self.openId, group_id: self.group_id, car_list: car_list, money: self.totalPrice },1).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        self.getGroupInfo();
                    } else {
                        self.group_status = data.data.group_status;
                        self.showDisable  = false;
                        self.showDisableModal();
                        self.carList = [];
                        return false
                    }
                });
            },
            inputSearch: function(){
                let storeData = {
                    carArray1  : event.objToArr(carArray1),
                }
                uni.setStorageSync("STOREDATA", storeData); 
              //  getApp().globalData.isRegisted = self.isRegisted;
                uni.navigateTo({
                    url: '/pagesGoods/goods/store-search/index?storeId=' + this.storeInfo.id + '&header=' + this.header + '&storeName=' + this.storeInfo.shop_name + '&groupId=' + this.group_id + '&sid=' + this.sid 
                  });
            },
            goCertificate: function () {
                var self = this;
                getApp().globalData.isRegisted = self.isRegisted;
                uni.navigateTo({
                    url: '/pagesGoods/goods/store-cert/index?storeId=' + this.storeInfo.id
                });
            },
            closeNavigation: function(){
                this.navigationClose = true;
            },
            goStoreDetail: function () {
                let arr = [];
                let activeList = this.activeList;
                activeList.map(function (i) {           
                    arr[i.type]= i.text
                });
                this.activeManjian = arr['manjian'] || '';
                this.activeDiscount = arr['discount'] || ''
                this.showStoreInfo = true;
            },
            hideStoreDetail: function(){
                this.showStoreInfo = false;
            },
            showGoodsDetail: function (e) {
                var index = e.currentTarget.dataset.index;
                var link  = e.currentTarget.dataset.link || 0;
                if(this.is_super == 1){
                    var goods = this.goodsList[index];
                }else{
                    var goods = this.goodsList[link][index];
                } 
                this.goodsDetail = {
                        show    : true,
                        src     : goods.icon,
                        title   : goods.allName,
                        info    : goods.allDesc,
                        num     : goods.buy_num,
                        price   : goods.price,
                        index   : index,
                        sel_out : goods.sel_out,
                        link    : link
                    }
            },
            closeGoodsDetail: function () {
                this.goodsDetail = {show:false};
            },
            addDetailCart: function(e){
                var index = e.currentTarget.dataset.index;
                var link  = e.currentTarget.dataset.link || '';
                this.goodsDetail = {show: false};
                this.addCart({currentTarget: {dataset: {index: index,link: link}}});
            },
            tabbarEvent: function (e) {
                var tabbarId = e;
                this.tabbarId = tabbarId;   
                if(e==3 && this.eval_list.length == 0){
                    this.loadStoreScore();
                    this.loadEvaluation();
                }
            },
            openNavigation: function(){
                if( !this.navigationClose || this.header == 'buy_together') return false;
                this.navigationClose = false;
            },
            getHeightList: function() {
            	let _this = this;
            	let selectorQuery = uni.createSelectorQuery();
            	selectorQuery.select('.left-content').boundingClientRect(function(rects) {
            		_this.left_height = rects.height;
            	});
            	selectorQuery.selectAll('.category-item').boundingClientRect(function(rects) {   
            		_this.right_height = rects.map((item) => item.top);
            	}).exec();
                setTimeout(function(){ _this.loadOver = false; },900);
                setTimeout(function(){ _this.hideOver = false; },1000); 
            },
            choose: function(e) {
                var self = this;
                var index = e.currentTarget.dataset.itemIndex;
                var link  = e.currentTarget.dataset.name;
            	this.select_index_ca = index;
            	// 加入防抖
            	if (this.timeout) {
            		clearTimeout(this.timeout); //清除计时器				
            	}
            	this.timeout = setTimeout(() => {
                    if(index>0){
                        self.right_scroll = self.right_height[index] - self.storeTop - 10;
                    }else{
                        self.right_scroll = self.right_height[index] - self.storeTop - 40;
                    }
            	}, 100)  
            }, 
            scrollMove: function(e){  
                let _this = this;
                this.navigationClose = true;
                if(this.categoryList.length >= this.right_height.length){
                    this.right_height.push(_this.right_height[_this.right_height.length-1]*2);
                }
                    //引入节流
                    let right_content_height = e.detail.scrollHeight - this.windowHeight;
                    if (right_content_height == e.detail.scrollTop) {
                    	return;
                    }
                    let scroll_top = e.detail.scrollTop + this.storeTop + 10; //距顶部的高度
                    //判断当前的scrollTop在哪个区间内;
                    let now = +new Date();
                    if (now - this.last > 100) {		
                    	this.last = now;
                    	let active_index = this.right_height.findIndex((value, index, arr) => value <= scroll_top && scroll_top < arr[index + 1]);
                        this.select_index    = active_index; 
                        this.select_index_ca = this.select_index < 0 ? 0 : this.select_index;
                    	if (this.left_height + this.storeTop + 110 - this.windowHeight>0) {
                    		//如果有超出部分
                    		let diff = this.left_height + 130 - this.windowHeight
                    		this.left_scroll = Math.round((active_index * diff) / (this.categoryList.length - 1));
                    	}
                    }    
            },
            scrollLeft(event) {
                this.navigationClose = true;
            },
            
            toggleList: function () {
                if ((this.header != "buy_together" && !this.totalCount) || (this.header == "buy_together" && this.totalCount_all == 0)) {   
                    return;
                }
                var self = this;
                var minPrice = self.storeInfo.start_send_price;
                var totalCount_all = 0;
                var must    = false;
                var mustSum = self.mustSum;
                var mustCid = self.mustCid;
                if ( self.cartShow == 'none' && self.header == "buy_together" ){
                    $api_base.post_new($api_base.groupInfo,{ wxapp_id: self.openId, group_id: self.group_id }).then(function(res) {
                        let data = res.data;
                        if (data.ok == 1) {
                            groupArray = data.data || [];
                            for (let i in groupArray) {
                                for (let j in groupArray[i].goods_list) {
                                    totalCount_all += groupArray[i].goods_list[j].num;
                                }
                            }
                            var total_money = data.total_money || 0;
                            var diff = minPrice - total_money;
                            diff = new Big(diff).round(2).toString();
                            var totalPrice = new Big(total_money).round(2).toString();
                            var orderList = data.order_list || [];
                            if (mustCid != 0) {
                                const index = orderList.findIndex(orderList => orderList.category_id == mustCid);
                                if (index >= 0) {
                                  must = false;
                                } else {
                                  must = true;
                                }
                            }
                            self.group_status = data.group_status;
                            self.groupList = data.data || [];
                            self.totalCount_all = totalCount_all;
                            self.totalPrice_all = parseFloat(totalPrice);
                            self.self_money = data.self_money || 0;
                            self.diffPrice = diff;
                            self.must = must;
                            self.newGoodsList();
                        }
                    }); 
                }
                this.fold = !this.fold;
                this.cartShowMethod(this.fold)
            },
            cartShowMethod: function (fold) {
                if (fold == false) {
                    this.cartShow = 'block';
                } else {
                    this.cartShow = 'none';
                }
            },
            selectSetting: function(e){
                var idx   = e.currentTarget.dataset.idx;
                var index = e.currentTarget.dataset.index;
                var item  = this.setting.item[idx];
                var value = item.value[index];
                var price = 0;
                item.value.map(function (i, k) {
                    if (i.id == value.id) {
                        item.value[k].current = 1;
                        price = i.price;
                    } else {
                        item.value[k].current = 0;
                    }
                });
                var setting = this.setting;
                setting.item[idx] = item;
                if (item.type === 'spec') {
                    setting.price = price;
                }    
                this.setting= [];
                this.setting = setting;
            },
            closeSetting: function() {
                this.setting = {show: false};
            },
            //差几元起送
            payDescFunc: function() {
                var self = this;
                var storeInfo = self.storeInfo;
                var carList   = self.carList;
                var sid       = self.sid;
                var listServiceType = getApp().globalData.listServiceType;
                var mustSum   = self.mustSum;
                var mustCid   = self.mustCid;
                self.listServiceType = listServiceType;
                if (self.sid === 'group' || self.sid === 'share_group') {
                    if (self.openGroupActive === false) {
                        return '暂无班次';
                    }
                }
                let l = carList.length;
                if(mustSum > 0){
                    if (l > 0) {
                      const index = carList.findIndex(carList => carList.category_id == mustCid);  
                       if (index < 0){
                          self.must = true;
                      //     return '下单前请选必选品';
                         }else{
                          if (self.totalPrice < minPrice){
                            var diff = minPrice - self.totalPrice;
                            diff = new Big(diff).round(2).toString();
                            self.must = false;
                            return '还差' + diff + '元起送';
                          }else{
                            self.must = false;
                            return '去结算';
                          }
                        }
                     }else{
                       self.must = true;
                      // return '下单前请选必选品';
                     }
                }
                  if (sid == "oneself" || listServiceType != 0 || self.storeInfo.open_oneself == 2) {  //自取
                      minPrice = self.storeInfo.invite_start_send_price || 0;
                  } else {
                      minPrice = self.storeInfo.start_send_price || 0;
                  }  
                    if (self.totalPrice === 0) {
                        if ( sid == "oneself" || listServiceType != 0 ) {  //自取     
                            return '￥'+minPrice+'元起自取';
                        }else{
                            if ( self.storeInfo.open_oneself == 2 ){
                                return '￥'+minPrice+'元起自取';
                            }else{
                                return '￥'+minPrice+'元起送'; 
                            }
                        }  
                    } else if (self.totalPrice < minPrice) {
                        var diff = minPrice - self.totalPrice;
                        diff = new Big(diff).round(2).toString();
                        if (sid == "oneself" || listServiceType != 0) {  //自取     
                            return '还差' + diff + '元自取';
                        } else {
                            if (self.storeInfo.open_oneself == 2){
                                return '还差' + diff + '元自取';
                            }else{
                                return '还差' + diff + '元起送';
                            }
                        }  
                    } else {
                        return '去结算';
                    }   
            },
            empty: function(e) {
                var self = this;
                var openId = self.openId;
                var header = self.header;
                var cartShow = '';
                var totalCount_all = 0;
                var isSearch = self.isSearch;
                uni.showModal({
                    content: '确定要清空购物车吗？',
                    success: function (res) {
                        if (res.confirm) {
                            if(header == 'buy_together'){
                                var groupList = self.groupList;
                                for( let i in groupList){
                                    if(openId == groupList[i].wxapp_id){
                                        groupList[i].goods_list.splice(0, groupList[i].goods_list.length)
                                    }
                                    totalCount_all += groupList[i].goods_list.length;
                                }
                                if (totalCount_all > 0) {
                                    cartShow = 'block';
                                } else {
                                    cartShow = 'none';
                                }
                                carArray1 = [];
                                self.carList = []; 
                                self.groupList = groupList; 
                                self.cartShow = cartShow;
                                self.confirmGoods();
                            }else{ 
                                if(self.is_super == 0){
                                    var goods = self.goodsList || [];
                                    for(let i in goods){
                                        for(let j in goods[i]){
                                            goods[i][j].Count = 0;
                                        }
                                    }
                                }else{
                                    var goods = self.goodsList || [];
                                    goods.map(function (i, K) {
                                        goods[K].Count = 0;
                                    });
                                } 
                                carArray1 = [];
                                carTmp = [];
                                orderNum = 0;
                                discountGoodsNum = 0;
                                self.carList = []; 
                                self.cartShow = 'none', 
                                self.goodsList = goods, 
                                self.calTotalPrice();
                                self.totalCount = 0;
                                self.totalPrice = 0;
                                self.payDesc    = self.payDescFunc();
                            } 
                            for(let i in self.categoryList){
                                self.categoryList[i].count = 0;
                            }
                        }
                    }
                })
            }, 	
            //规格设置
            settingInsert:function() {    //选好了触发
                var setting = this.setting;
                var isSearch = this.isSearch;
                if(this.is_super == 1){
                    this.goodsList[setting.index].setting = setting.item;
                    this.insertCart(this.goodsList[setting.index], setting.index, setting.link);
                }else{
                    this.goodsList[setting.link][setting.index].setting = setting.item;
                    this.insertCart(this.goodsList[setting.link][setting.index], setting.index, setting.link);
                }
                this.closeSetting();    
            },
            addCart: function(e){
                var index = e.currentTarget.dataset.index;   //加号index
                var goods = '';
                if(this.is_super == 1){
                    var link = this.categoryInfo.name;
                    goods    = this.goodsList[index];   //当前选中商品   
                }else{
                    var link = e.currentTarget.dataset.link || 0;
                    goods    = this.goodsList[link][index];   //当前选中商品   
                } 
                var spec = goods.spec || [];
                var attr = goods.attr || [];        
                var item = [];
                if (spec.length > 0) {   //规格属性
                    var price = 0;
                    var isFirst = 1;
                    spec.map(function (i, k) {
                        if (i.num > 0 && isFirst) {
                            isFirst = 0;
                            spec[k].current = 1;
                            price = i.price;
                        } else spec[k].current = 0;
                    });
                    item.push({"name": "规格", "value": spec, "type": "spec"});
                }
                if (attr.length > 0) {   //规格属性
                    attr.map(function (i) {
                        var attribute = i.attribute.split('|');
                        var valueObj = [];
                        attribute.map(function (name, id) {
                            valueObj.push({"name": name, "id": id, 'attr_id': i.id, "price": 0, "current": id === 0 ? 1 : 0});
                        });
                        item.push({"name": i.name, 'attr_id': i.id, "value": valueObj, "type": "attr"});
                    });
                }
                if (item.length > 0) {
                    this.setting = {show: true, item: item, index: index, name: goods.name, price: price, link: link}
                } else {
                    this.insertCart(goods, index, link)
                }
            },
            addCartGoods: function(e) {   //购物车➕ 点击事件
                var self  = this;
                var key   = e.currentTarget.dataset.key;
                var id    = e.currentTarget.dataset.id;
                var link  = e.currentTarget.dataset.link || 0;
                var goods = [];
                if(this.is_super == 1){
                    goods = this.goodsList || [];
                }else{
                    goods = this.goodsList[link] || [];
                }
                var isSelOut = 0;
                var isFind = false;
                this.goodsKeyAd = key; 
                this.goodsKeySub = '';
                if (this.header != 'buy_together') {
                    if (carArray1[key].stdClass.spec !== undefined) {
                        if(this.is_super == 1){
                            goods.map(function (i, K) {
                                if (i.id === id) {
                                    isFind = true;
                                    var selOut = 1;
                                    i.spec.map(function (n, m) {
                                        if (carArray1[key].stdClass.spec.id == n.id) {
                                            if (goods[K].spec[m].num <= 0) {
                                                isSelOut = 1;
                                            } else {
                                                goods[K].spec[m].num--;
                                            }
                                        }
                                        var num = goods[K].spec[m].num;
                                        if (num > 0) selOut = 0;
                                        goods[K].sel_out = selOut;
                                    });
                                }
                            });
                        }else{
                            for(let n in this.goodsList){
                                for(let l in this.goodsList[n]){
                                    if(id == this.goodsList[n][l].id){
                                        isFind = true;
                                        var selOut = 1;
                                        this.goodsList[n][l].spec.map(function(i,m) {
                                            if (carArray1[key].stdClass.spec.id == i.id) {
                                                if (self.goodsList[n][l].spec[m].num <= 0) {
                                                    isSelOut = 1;
                                                } else {
                                                    self.goodsList[n][l].spec[m].num--;
                                                }
                                            }
                                            var num = self.goodsList[n][l].spec[m].num;
                                            if (num > 0) selOut = 0;
                                            self.goodsList[n][l].sel_out = selOut;
                                        }); 
                                    }
                                }
                            }
                        } 
                        if (!isFind) {
                            if (carArray1[key].num - carArray1[key].stdClass.spec.maxNum >= 0) {
                                isSelOut = 1;
                            }
                        }
                    } else {
                        var selOut = 1;
                        if(this.is_super == 1){
                            goods.map(function (i, K) {
                                if (i.id === id) {
                                    isFind = true;
                                    if (goods[K].num <= 0) {
                                        isSelOut = 1;
                                    } else {
                                        goods[K].num--;
                                    }
                                    var num = goods[K].num;
                                    if (num > 0) selOut = 0;
                                    goods[K].sel_out = selOut;
                                }
                            });
                        }else{
                            for(let n in this.goodsList){
                                for(let l in this.goodsList[n]){
                                    if(id == this.goodsList[n][l].id){
                                        isFind = true;
                                        if(this.goodsList[n][l].num <= 0){
                                            isSelOut = 1;
                                        }else{
                                            this.goodsList[n][l].num--;
                                        }
                                        var num = this.goodsList[n][l].num;
                                        if (num > 0) selOut = 0;
                                        this.goodsList[n][l].sel_out = selOut;  
                                    }
                                }
                            }
                        }
                        if (!isFind) {
                            if (carArray1[key].num - carArray1[key].goods.maxNum >= 0) {
                                isSelOut = 1;
                            }
                        }
                    }
                    if (isSelOut > 0) {
                        uni.showToast({title: '已售完', icon: 'none', duration: 2000});
                        return false;
                    }
                    if(this.is_super == 0){
                        for(let n in this.goodsList){
                            for(let l in this.goodsList[n]){
                                if(id == this.goodsList[n][l].id){
                                    this.goodsList[n][l].Count++;
                                        self.categoryList[n].count++;
                                   
                                }
                            }
                        }
                    }else{
                        goods.map(function (i, K) {
                            if (i.id === id) {
                                goods[K].Count++;
                            }  
                        });

                        // const index = self.school_list.findIndex(item => item === self.schoolId);
                        // console.log(link);
                        // console.log(self.categoryList[link]);
                        // self.categoryList[link].count++;
                    }
                    carTmp.unshift({id: id, key: key});
                    carArray1[key].num = carArray1[key].num + 1;
                    this.callCarPrice(key);
                }
                this.callCarList();
                this.goodsList[link] = goods;
                this.cartShow = 'block';
                this.calTotalPrice();
                this.payDesc = this.payDescFunc();
            },
            decreaseCart: function (e) { 
                var self        = this;
                var index       = e.currentTarget.dataset.index;
                var id          = e.currentTarget.dataset.id;
                var link        = e.currentTarget.dataset.link;
                var fullCount   = self.storeInfo.full_count || 0;
                var delKey      = null;
                var goodsList   = []; 
                
                if(this.is_super == 1){
                    goodsList = this.goodsList || [];   //当前选中商品
                }else{
                    goodsList = this.goodsList[link] || [];
                } 
                if(this.header != 'buy_together'){
                    for (var k in carTmp) {
                        if (carTmp[k].id == id) {
                            delKey = carTmp[k].key;
                            carTmp.splice(k, 1);
                            break;
                        }
                    }
                    if (delKey === null || carArray1[delKey] === undefined) return false;
                    if (carArray1[delKey].stdClass.spec !== undefined) {
                        if(self.is_super == 0){
                            for(let i in this.goodsList){
                                for(let l in this.goodsList[i]){
                                    if(id == this.goodsList[i][l].id){
                                        this.goodsList[i][l].Count--;
                                        self.categoryList[i].count--;
                                    }
                                }
                            }
                        }else{
                            // goodsList[index].Count--;
                            // self.categoryList[self.categoryIndex].count--;
                        }  
                        goodsList[index].spec.map(function (n, m) {
                            if (carArray1[delKey].stdClass.spec.id == n.id) {
                                goodsList[index].spec[m].num++;
                            }
                            var num = goodsList[index].spec[m].num;
                            if (num > 0) goodsList[index].sel_out = 0;
                        });
                    } else {
                        if(self.is_super == 0){
                            for(let i in this.goodsList){
                                for(let l in this.goodsList[i]){
                                    if(id == this.goodsList[i][l].id){
                                        this.goodsList[i][l].Count--;  
                                        this.goodsList[i][l].num++;
                                        self.categoryList[i].count--;
                                    }
                                }
                            }
                        }else{
                            // goodsList[index].Count--;
                            // goodsList[index].num++;
                            // self.categoryList[self.categoryIndex].count--;
                        }
                        var num = goodsList[index].num;
                        if (num > 0) goodsList[index].sel_out = 0;
                    }
                    if (carArray1[delKey].num - 1 === 0) {  //商品清零
                        var numDiscount = carArray1[delKey].goods.discount.num_discount || 0;   //折扣限购份数
                        var openDiscount = carArray1[delKey].goods.open_discount || 0;
                    // if (numDiscount > 0 && openDiscount > 0 && carArray1[delKey].discountNum > 0) discountGoodsNum--;
                        if (numDiscount > 0 && openDiscount > 0) discountGoodsNum--;  //享受折扣的数
                        delete carArray1[delKey];            
                    } else {
                        carArray1[delKey].num = carArray1[delKey].num - 1;
                        this.callCarSubPrice(delKey);
                    }
                    discountGoodsNum = 0;  //已享受的折扣
                    var goodsDiscount = this.storeInfo.goods_discount || 0;  //总共折扣限购份数
                    for (var k in carArray1) {
                        var num_discount = carArray1[k].goods.discount.num_discount || 0; //该商品折扣限购份数
                        var lastDiscount1 = goodsDiscount - discountGoodsNum;   //总共剩余的折扣份数
                        var showPrice = carArray1[k].showPrice || carArray1[k].price;
                        var openDiscount = carArray1[k].goods.open_discount;

                        if (lastDiscount1 > 0 && fullCount < 3) {  //还有可折扣数
                            if (num_discount > 0 && openDiscount > 0) { //该商品有可折扣数
                                if (carArray1[k].num <= num_discount) { // 该商品购买量 小于 该商品折扣份数
                                    carArray1[k].money = carArray1[k].num * carArray1[k].price;
                                    discountGoodsNum += carArray1[k].num;
                                    carArray1[k].discountNum = carArray1[k].num;
                                } else {  //该商品购买量 大于 该商品折扣份数
                                    let t1 = num_discount * carArray1[k].price;
                                    let t2 = carArray1[k].num - num_discount
                                    carArray1[k].money = t1 + t2 * showPrice;
                                    discountGoodsNum += num_discount;
                                    carArray1[k].discountNum = num_discount;
                                }
                            } else {
                                num_discount = 0;
                                carArray1[k].money = carArray1[k].num * showPrice;
                            }
                        } else {  //没有折扣了 
                            lastDiscount1 = 0;
                            carArray1[k].money = carArray1[k].num * showPrice;
                            discountGoodsNum += 0;
                            carArray1[k].discountNum = 0;
                        }
                    } 
                    if(this.is_super == 1){
                        this.goodsList = goodsList;
                    }else{
                        this.goodsList[link] = goodsList;
                    }
                } 
                this.goodsKeySub = id;
                this.goodsKeyAd  = '';
                this.callCarList();
                this.calTotalPrice();
                this.payDesc = self.payDescFunc();
                //关闭弹起
                if (carTmp.length === 0 && this.header != 'buy_together') {
                    this.cartShow = 'none';
                }
            },
            subCartGoods:function(e) {
                var self = this;
                var key       = e.currentTarget.dataset.key;
                var id        = e.currentTarget.dataset.id;
                var fullCount = this.storeInfo.full_count || 0;
                var goods     = [];
                var link      = e.currentTarget.dataset.link || '';
                if(this.is_super == 0){    
                    goods     = this.goodsList[link] || [];
                }else{
                    goods     = this.goodsList || [];
                } 
                this.goodsKeySub = key;
                this.goodsKeyAd = '';
                for (var k in carTmp) {
                    if (carTmp[k].key === key) {
                        carTmp.splice(k, 1);
                        break;
                    }
                }
                if(this.is_super == 0){
                    for(let n in self.goodsList){
                        for(let l in self.goodsList[n]){
                            if(id == self.goodsList[n][l].id){
                                self.goodsList[n][l].Count--;
                                self.goodsList[n][l].num++; 
                                    self.categoryList[n].count--;
                            }
                        }
                    }
                }
                
                if (this.header != "buy_together"){
                    if (key === '' || carArray1[key] === undefined) return false;
                    if (carArray1[key].stdClass.spec !== undefined) {
                        goods.map(function (i, K) {
                            if (i.id === id) {
                                if(self.is_super == 1){
                                    goods[K].Count--;
                                    //self.categoryList[k].count--;
                                }
                                i.spec.map(function (n, m) {
                                    if (carArray1[key].stdClass.spec.id == n.id) {
                                        goods[K].spec[m].num++;
                                    }
                                    var num = goods[K].spec[m].num;
                                    if (num > 0) goods[K].sel_out = 0;
                                });
                            }
                        });
                    } else {
                        goods.map(function (i, K) {
                            if (i.id === id) {
                                if(self.is_super == 1){
                                    goods[K].Count--;
                                    goods[K].num++;
                                    
                                } 
                            }
                            var num = goods[K].num;
                            if (num > 0) goods[K].sel_out = 0;
                        });
                        
                       // self.categoryList[link].count--;
                        
                    }
                    if (carArray1[key].num - 1 === 0) {
                        var numDiscount = carArray1[key].goods.discount.num_discount || 0;
                        var openDiscount = carArray1[key].goods.open_discount || 0;
                        if (numDiscount > 0 && openDiscount > 0) discountGoodsNum--;
                        delete carArray1[key];
                    } else {
                        carArray1[key].num = carArray1[key].num - 1;
                        this.callCarSubPrice(key);
                    }
                    discountGoodsNum = 0;  //已享受的折扣
                    var goodsDiscount = this.storeInfo.goods_discount || 0;  //总共折扣限购份数
                    for (var k in carArray1) {
                        var num_discount = carArray1[k].goods.discount.num_discount || 0; //该商品折扣限购份数
                        var lastDiscount1 = goodsDiscount - discountGoodsNum;   //总共剩余的折扣份数
                        var showPrice = carArray1[k].showPrice || carArray1[k].price;
                        var open_discount = carArray1[k].goods.open_discount;

                        if (lastDiscount1 > 0 && fullCount < 3) {  //还有可折扣数
                            if (num_discount > 0 && open_discount > 0) { //该商品有可折扣数
                                if (carArray1[k].num <= num_discount) { // 该商品购买量 小于 该商品折扣份数
                                    carArray1[k].money = carArray1[k].num * carArray1[k].price;
                                    discountGoodsNum += carArray1[k].num;
                                    carArray1[k].discountNum = carArray1[k].num;
                                } else {  //该商品购买量 大于 该商品折扣份数
                                    let t1 = num_discount * carArray1[k].price;
                                    let t2 = carArray1[k].num - num_discount
                                    carArray1[k].money = t1 + t2 * showPrice;
                                    discountGoodsNum += num_discount;
                                    carArray1[k].discountNum = num_discount;
                                }
                            } else {
                                num_discount = 0;
                                carArray1[k].money = carArray1[k].num * showPrice;
                            }
                        } else {  //没有折扣了 
                            lastDiscount1 = 0;
                            carArray1[k].money = carArray1[k].num * showPrice;
                            discountGoodsNum += 0;
                            carArray1[k].discountNum = 0;
                        }
                    } 
                }
                if(this.is_super == 0){
                    this.goodsList[link] = goods;
                }else{
                    this.goodsList = goods;
                } 
                this.callCarList();
                this.calTotalPrice();
                this.payDesc = this.payDescFunc();
                //关闭弹起
                if ( this.header != "buy_together" && carTmp.length === 0 ){
                    this.cartShow = 'none';
                }else{
                    this.cartShow = 'block';
                }   
            },
            //添加到购物车
            insertCart: function(goods, index, link){ 
                var stdClass = new Object();
                var hashStr = '';
                var goodsList = [];
                var self = this;
                var header = self.header;
                if(this.is_super == 1){
                    goodsList = this.goodsList || [];   // 菜单列表
                    goodsList[index].Count++;   //当前菜品选中的个数
                   // self.categoryList[self.categoryIndex].count++;
                }else{
                    goodsList = this.goodsList[link] || [];   // 当前品类菜单列表   
                    for(let i in this.goodsList){
                        for(let l in this.goodsList[i]){
                            if(goods.id == this.goodsList[i][l].id){
                                this.goodsList[i][l].Count++;
                                self.categoryList[i].count++;
                            }
                        }
                    }
                }
                hashStr += goods.id + '-';
                //总金额
                var priceIncr = goods.price;  //价格
                var showPriceIncr = goods.show_price || 0;   //原价
                var settingArr = [];  // 后端验证的描述信息集合
                var showDesc = [];   //显示的 描述信息集合
                var isSpec = 0;
                //价格计算
                if (goods.setting !== undefined && goods.setting.length > 0) {
                    goods.setting.map(function (e) {
                        if (e.type === 'spec' && e.value.length > 0) {
                            isSpec = 1;
                            e.value.map(function (i) {
                                if (i.current === 1) {
                                    priceIncr = i.price;
                                    showPriceIncr = i.show_price;
                                    stdClass.spec = i;
                                    hashStr += i.id + '-';
                                    if (i.name !== 'x') showDesc.push(i.name);
                                    settingArr.push(i.name);
                                    goodsList[index].spec.map(function (m, M) {
                                        if (m.id == i.id) {
                                            goodsList[index].spec[M].num--;
                                        }
                                    });
                                }
                                var selOut = 1;
                                goodsList[index].spec.map(function (m, M) {
                                    var num = goodsList[index].spec[M].num;
                                    if (num > 0) selOut = 0;
                                    goodsList[index].sel_out = selOut;
                                });
                            });
                        }
                        if (e.type === 'attr' && e.value.length > 0) { 
                            e.value.map(function (i, k) {
                                if (i.current === 1) {
                                    if (stdClass.attr === undefined) {
                                        stdClass.attr = [];
                                    }
                                    stdClass.attr.push(i);
                                    hashStr += i.name + '-';
                                    if (i.name !== 'x') {
                                        showDesc.push(i.name);
                                    }
                                    settingArr.push(i.name);
                                }
                            });
                        }
                    });
                }
                if (isSpec === 0) {
                    goodsList[index].num--;
                    if (goodsList[index].num <= 0) {
                        goodsList[index].sel_out = 1;
                    }
                }
                hashStr = md5.hex_md5(hashStr);
                if (carArray1[hashStr] === undefined) {
                    orderNum++;
                    carArray1[hashStr] = {
                        id             : goods.id, 
                        orderNum       : orderNum, 
                        discountNum    : 0, 
                        discount_id    : goods.discount.discount_id || 0,
                        open_discount  : goods.open_discount,
                        goods          : goods, 
                        stdClass       : stdClass,
                        key            : hashStr, 
                        price          : priceIncr,      //折后价格
                        showPrice      : showPriceIncr,   //原价
                        num            : 1,            //购买数量
                        money          : 0,            //应付价格
                        index          : index,
                        desc           : settingArr.join('，'), 
                        showDesc       : showDesc.join('，'),
                        box_id         : goods.box_id,
                        food_box_money : goods.food_box_money,
                        category_id    : goods.category_id,
                        link           : link
                    };
                    self.callCarPrice(hashStr);
                } else {
                    carArray1[hashStr].num = carArray1[hashStr].num + 1;
                    self.callCarPrice(hashStr);
                }
                if(self.header == "buy_together"){
                    carArray1[hashStr].num = 1;
                }
                let tmpcar={
                    id             : carArray1[hashStr].id,
                    orderNum       : carArray1[hashStr].orderNum,
                    discountNum    : carArray1[hashStr].discountNum,
                    discount_id    : carArray1[hashStr].discount_id,
                    open_discount  : goods.open_discount,
                    name           : carArray1[hashStr].goods.name,
                    stdClass       : carArray1[hashStr].stdClass,
                    key            : carArray1[hashStr].key,
                    num            : carArray1[hashStr].num,
                    desc           : carArray1[hashStr].desc,
                    showDesc       : carArray1[hashStr].showDesc,
                    price          : carArray1[hashStr].price,
                    box_id         : carArray1[hashStr].box_id,
                    food_box_money : carArray1[hashStr].food_box_money,
                    category_id    : carArray1[hashStr].category_id,
                    link           : carArray1[hashStr].link
                };
                carTmp.unshift({id: goods.id, key: hashStr});
                
                if(this.is_super == 1){
                    this.goodsList = goodsList;
                }else{
                    this.goodsList[link] = goodsList;
                }
                this.goodsAdd    = tmpcar;
                this.goodsKeySub = '';
                this.goodsKeyAd  = '';
                this.callCarList();
                this.calTotalPrice();
                this.payDesc = this.payDescFunc();
            },
            callCarSubPrice: function (hashStr) {   //减号商品不清零价格计算
                var price = carArray1[hashStr].price;
                var showPrice = carArray1[hashStr].showPrice || 0;
                var buyNum = carArray1[hashStr].num;   //该商品购买量
                let goodsDiscount = this.storeInfo.goods_discount || 0;  //总共折扣限购份数
            },
            callCarPrice: function (hashStr) {   //添两个➕ 时触发的价格计算
                var price = Number(carArray1[hashStr].price);   //折扣价
                var showPrice = Number(carArray1[hashStr].showPrice) || 0;  //原价
                var buyNum = carArray1[hashStr].num;   // 购买数量
                if (carArray1[hashStr].goods.open_discount > 0) {
                    var numDiscount = carArray1[hashStr].goods.discount.num_discount || 0;
                    var share_discount = carArray1[hashStr].goods.discount.share_discount || 0;
                    var goodsDiscount = this.storeInfo.goods_discount || 0;        //总共可折扣份数
                    if (numDiscount > 0 && buyNum === (numDiscount + 1) && showPrice > 0 && (goodsDiscount <= 0 || (goodsDiscount - discountGoodsNum) > 0)) {
                        uni.showToast({title: '折扣菜品限购' + numDiscount + '份，超出' + numDiscount + '份恢复原价', icon: "none"});
                    } else if (goodsDiscount > 0 && (goodsDiscount - discountGoodsNum) === 0) {
                        uni.showToast({title: '每单折扣商品限购' + goodsDiscount + '份，超出' + goodsDiscount + '份恢复原价', icon: "none"});
                    } else if (buyNum === 1 && share_discount == 0) {
                        uni.showToast({title: '满减与折扣商品不同享', icon: "none"});
                    }
                    if (numDiscount > 0 && (buyNum > numDiscount || (goodsDiscount > 0 && (goodsDiscount - discountGoodsNum) == 0)) && showPrice > 0) {
                        carArray1[hashStr].money += showPrice;
                    } else {
                        carArray1[hashStr].money += price; //折扣方式计算 购买数量不大于限制
                        carArray1[hashStr].discountNum++;
                        discountGoodsNum++;
                    }
                } else {
                    carArray1[hashStr].money += price; //不带折扣方式计算
                }
            },
            callCarList: function () {  //购物车列表
                var self = this;
                var carList = [];
                var cartShow = self.cartShow;
                var packageFee = self.storeInfo.package_bag_money;
                for (var k in carArray1) {
                    carArray1[k].money = parseFloat(new Big(carArray1[k].money).round(2).toString());
                    if (self.header != "buy_together") {
                        carList.push(carArray1[k]);
                    }
                }
                if (self.header == "buy_together") {
                    self.changeGroupList();
                }
                for(let i in carList){
                    let fee = carList[i].food_box_money * carList[i].num
                    packageFee += fee;
                }
                packageFee = parseFloat(new Big(packageFee).round(2).toString());
                this.carList = carList;
                this.packageFee = packageFee;
            },
            //计算总价
            calTotalPrice: function () {
                var totalPrice = 0;
                var totalCount = 0;
                var packageFee = this.packageFee;
                var must = false;
                for (var k in carArray1) {
                    totalPrice += carArray1[k].money;
                    totalCount += carArray1[k].num;
                }
                if (totalCount == 0 ){
                    packageFee = 0;
                }
                totalPrice = new Big(totalPrice + packageFee).round(2).toString();
                let l = carArray1.length;
                if (l > 0) {
                  if (data.must_cid != 0) {
                    const index = carArray1.findIndex(carArray1 => carArray1.category_id == mustCid);
                    if (index > 0) {
                      must = false;
                    } else {
                      must = true;
                    }
                  }
                }
                this.totalPrice = parseFloat(totalPrice); 
                this.totalCount = totalCount;
                this.must = must;
            },
            changeGroupList: function(){
                var self = this;
                var carList = [];
                var groupList = self.groupList;
                var goodsAdd = self.goodsAdd;
                var goodsKeySub = self.goodsKeySub;
                var goodsKeyAd = self.goodsKeyAd;  //购物车添加商品的id
                var group_status = self.group_status;
                if(groupList.length==0){
                    carList.push(goodsAdd);
                }else{
                    for (let m in groupList) {   //添加新增的菜单
                        if (groupList[m].wxapp_id == self.openId) { //当前用户
                            if (groupList[m].goods_list.length > 0) {
                                let ex = false;
                                let index = 0;
                                let subIndex = 0;
                                for (let a in groupList[m].goods_list) {
                                    if (goodsKeySub == '' && goodsKeyAd == '') {
                                        if (goodsAdd.id == groupList[m].goods_list[a].id && goodsAdd.showDesc == groupList[m].goods_list[a].showDesc) {
                                            index = a;
                                            ex = true;
                                        }
                                    } else if (goodsKeyAd == '') {
                                        if (goodsKeySub == groupList[m].goods_list[a].key) { //购物车减
                                            if (group_status == 1){
                                                groupList[m].goods_list[a].num--;
                                                if (groupList[m].goods_list[a].num < 1) {
                                                    groupList[m].goods_list.splice(a, 1);
                                                }
                                            }   
                                        } else if (goodsKeySub == groupList[m].goods_list[a].id) {  //商品减
                                            if (group_status == 1){
                                                groupList[m].goods_list[a].num--;
                                                if (groupList[m].goods_list[a].num < 1) {
                                                    groupList[m].goods_list.splice(a, 1);
                                                }
                                            }   
                                            break;
                                        }
                                    } else if (goodsKeySub == '') {     //购物车加
                                        if (goodsKeyAd == groupList[m].goods_list[a].key) {
                                            if (group_status == 1)
                                                groupList[m].goods_list[a].num++;
                                        }
                                    }
                                }
                                if (goodsKeySub == '' && goodsKeyAd == '') {
                                    if (ex) {
                                        if (group_status == 1)
                                            groupList[m].goods_list[index].num++;
            
                                    } else {
                                        groupList[m].goods_list.push(goodsAdd);
                                    }
                                }
                            } else {
                                groupList[m].goods_list.push(goodsAdd);
                            }
                            carList = groupList[m].goods_list;
                        }
                    }
                }
                this.carList = carList;
                this.groupList = groupList;
                this.confirmGoods();
            },
            pay:function() {         
                if (this.header != "buy_together"){
                    if (this.totalPrice < minPrice || this.totalPrice === 0 || this.payDesc == '下单前请选必选品' || this.must) {
                        return;
                    }
                    if (this.sid === 'group' || this.sid === 'share_group') {
                        if (this.openGroupActive === false) {
                            return;
                        }
                    }
                }
                getApp().carData = {
                    storeId: this.storeId,
                    storeInfo: this.storeInfo,
                    carList: this.carList,
                    groupList: this.groupList
                };
                this.toPay = false;
                var self = this;
                var sid = self.sid;
                var listServiceType = getApp().globalData.listServiceType;
                if (this.header == "buy_together") {
                    if (self.is_master){ 
                      var serviceType = listServiceType ? listServiceType : 0;
                      if(listServiceType == '' ){
                        if (sid == "oneself" && self.storeInfo.open_oneself > 0) {
                          serviceType = self.storeInfo.open_oneself;
                        }
                      } 
                       $api_base.post($api_base.submitGroup,{ wxapp_id: self.openId, group_id: self.group_id, service_type: serviceType, item: 1}).then(function(res) { //发起人比较实付价格和起送价
                            let e = res.data;
                            if (e.ok == 1) {
                                $api_base.post_new($api_base.checkGroup,{ wxapp_id: self.openId, group_id: self.group_id}).then(function(re) {
                                    let data =re.data;
                                    if (data.ok == 2) {
                                        var stillCheckList = [];
                                        stillCheckList = data.data;
                                        self.showCheckGroup = true; 
                                        self.stillCheckList = stillCheckList
                                        self.toPay = false;
                                    } else {
                                        uni.showModal({
                                            title: '确定去结算吗？',
                                            content: '去结算后，其他人将不可加入或修改商品',
                                            cancelText: '取消',
                                            confirmText: '确认',
                                            confirmColor: '#00B89D',
                                            success(res) {
                                                if (res.confirm) {
                                                    self.toPay = true;
                                                    self.realPay();
                                                } else if (res.cancel) {
                                                    return false
                                                }
                                            }
                                        })
                                    }
                                });   
                            }else if (e.ok == 3){
                                uni.showToast({ title: '当前应付价为'+e.current_price+'元，低于店铺起送价', icon: "none", duration: 2000 })
                                return false;
                            }else{
                                uni.showToast({ title: e.msg, icon: "none", duration: 2000 })
                                return false;
                            }
                        })           
                    }else{
                        $api_base.post_new($api_base.groupInfo,{ wxapp_id: self.openId, group_id: self.group_id}).then(function(res) {
                            let data = res.data;
                            if (data.ok == 1) {
                                self.group_status = data.group_status;
                                if (data.group_status >2 ) {
                                    self.showDisableModal();
                                    return false;
                                } else {
                                    self.toPay = true;
                                    self.realPay();
                                }
                            }
                        })
                    }
                }else{
                    uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + this.sid + '&aid=' + this.aid + '&listServiceType=' + getApp().globalData.listServiceType });
                    getApp().globalData.isRegisted = self.isRegisted;
                }
            },
            closeCheckGroup: function(){
                this.showCheckGroup = false;
            },
            toPayFunc: function(){
                this.toPay = true;
                this.realPay();
            },      
            realPay:function(){
                var self = this;
                var is_master = self.is_master;
                getApp().globalData.isRegisted = self.isRegisted;
                if(!is_master && self.group_status == 2){
                    
                    uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + self.sid + '&aid=' + self.aid + '&header=' + self.header + '&groupId=' + self.group_id + '&is_master=' + self.is_master + '&listServiceType=' + getApp().globalData.listServiceType });
                }else{
                    $api_base.post_new($api_base.changeStatus,{ wxapp_id: self.openId, group_id: self.group_id, status: 2 }).then(function(res) {
                        let data = res.data;
                        if (data.ok == 1) {
                            if (is_master) {
                                self.showCheckGroup = false;
                            }
                            uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + self.sid + '&aid=' + self.aid + '&header=' + self.header + '&groupId=' + self.group_id + '&is_master=' + self.is_master + '&listServiceType=' + getApp().globalData.listServiceType });
                        } else {
                            if(!is_master){
                                uni.navigateTo({ url: '/pagesBuy/buy/buy/index?sid=' + self.sid + '&aid=' + self.aid + '&header=' + self.header + '&groupId=' + self.group_id + '&is_master=' + self.is_master + '&listServiceType=' + getApp().globalData.listServiceType });
                            }else{
                                uni.showToast({ title: '跳转失败，请重新点击去结算', icon: 'none', duration: 2000 });
                                return false;
                            }
                        }
                    });
                } 
            },
            groupRuleEvent: function () {
                this.showGroupRule = true;
            },
            groupRuleClose1: function () {
                this.showGroupRule = false;
            },
            goGroupList: function(){
                uni.navigateTo({
                    url: '/pagesOther/group-active/index?schoolId=' + schoolId,
                })
                getApp().globalData.isRegisted = this.isRegisted;
            },
            goMobile: function () {
                uni.makePhoneCall({
                    phoneNumber: this.storeInfo.mobile
                });
            },
            showGroupNotice: function(){
                var self = this;
                var content = '';
                if(self.currentInfo.current_finishTime && self.storeInfo.address){
                    content = '现在下单，'+ self.currentInfo.current_finishTime +'送达，'+self.storeInfo.address+'取餐'
                }else if(self.currentInfo.current_finishTime){
                    content = '现在下单，'+ self.currentInfo.current_finishTime +'送达';
                }else if(self.storeInfo.address){
                    content = '现在下单，'+ self.storeInfo.address +'取餐';
                }
                 uni.showModal({
                    title: '',
                    content: content,
                    showCancel: false,
                    confirmText: '知道了',
                    confirmColor: '#12D195',
                    success(res) {
                       
                    }
                })
            },
            getUserInfo: function(e) {   //参与者点选好了获取用户信息
                var self = this;
                var showGetUser_1 = self.showGetUser_1;
                var showGetUserStorage = uni.getStorageSync('showGetUserStorage') || '0';   
                uni.getUserInfo({
                    withCredentials: true,//此处设为true，才会返回encryptedData等敏感信息
                    success: res => {
                        this.nickName = res.userInfo.nickName;
                        this.face = res.userInfo.avatarUrl;
                        $api_base.post($api_base.getUser,{ nickname: res.userInfo.nickName, face: res.userInfo.avatarUrl, gender: res.userInfo.gender }).then(function(res) {
                            let data = res.data;
                            if (data.ok == 1) {
                                self.showGetUser_1 = false;
                                self.showGetUserStorage = 1;
                                uni.setStorageSync('showGetUserStorage', '1');
                                self.pay();
                            } else if (data.ok == -1) {
                                uni.showToast({ title: '用户信息获取失败，请重新获取', icon: 'none', duration: 2000 });
                                return false;
                            }
                        });
                    },
                    fail: res => {
                        self.showGetUser_1 = false;
                        self.showGetUserStorage = 1;
                        uni.setStorageSync('showGetUserStorage', '1');   //本地存储不再获取用户信息
                        self.pay();
                    }
                });      
            },
            loadStoreScore: function(){
                var self = this;
                $api_base.post($api_base.storeScore,{ s_id:self.storeId},1).then(function(res) {
                   let data = res.data;
                   if (data.ok == 1) {
                        self.score   = data.data.score || 0;
                        self.pack    = data.data.pack || 0;
                        self.taste   = data.data.taste || 0;
                        self.on_time = data.data.on_time || 0;
                        self.packInt = parseInt(self.pack);
                        self.packFloat = (self.pack%1).toFixed(1).split('.')[1];
                        self.tasteInt = parseInt(self.taste);
                        self.tasteFloat = (self.taste%1).toFixed(1).split('.')[1];
                    }
                });
            },
            loadEvaluation: function(){
                var self = this;
                var page = self.evalPage;
                var limit= self.evalLimit;
                $api_base.post($api_base.storeEvaluationList,{ s_id:self.storeId,s_type:self.s_type,is_content:self.is_content,page:page,limit:limit }).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        var evalList = data.data.evaluation_list || [];
                        if(evalList.length>0){
                            for(let i in evalList){
                                evalList[i].imageList = [];
                        		evalList[i].imageList  = evalList[i].image;
                                // if(evalList[i].image.indexOf('分隔符')){
                                //     evalList[i].imageList.push(evalList[i].image);
                                // }else{
                                //     evalList[i].imgList  = evalList[i].image.split('分隔符');
                                // }
                            }
                        }
                        
                        if(self.evalPage == 0){
                        	self.eval_list = evalList;
                        }else{
                        	 self.eval_list  = [...self.eval_list,...evalList] || [];
                        }
                        self.eva_count        = data.data.count_list.count || 0;
                        self.eva_good_count   = data.data.count_list.good || 0;
                        self.eva_middle_count = data.data.count_list.middle || 0;
						self.eva_image_count  = data.data.count_list.images || 0;
                        self.eva_bad_count    = data.data.count_list.bad || 0;
                        self.evalPage         = data.page || 1;
                    }
                });
            },
            updateEvalList: function(){ 
                var pn = this.evalPage;
                var pc = this.evalPage;
                var count = this.eval_list.length;
                if (pn * pc <= count) {
                    this.evalPage++
                    this.loadEvaluation();
                } else {
                    this.noMore = true;
                }
            },
            typeEvaluation: function(e){
                this.s_type = e;
                this.evalPage = 0;
                this.loadEvaluation();
            },
            showContent: function(){
               this.is_content = this.is_content == 2 ? '1' : '2';
               this.evalPage = 0;
               this.loadEvaluation();
            },
            saveInfo: function(){
                var carList = this.carList;
                var tmpCar2 = this.categoryList;
                var tmpcar  = [];
                var categoryList = JSON.stringify(tmpCar2);
                
                carList.map(function (i) {
                    tmpcar.push({
                        id: i.id,
                        orderNum: i.orderNum,
                        discount_id: i.discount_id,
                        discountNum: i.discountNum,
                        name: i.goods.name,
                        stdClass: i.stdClass,
                        key: i.key,
                        num: i.num,
                        showDesc: i.showDesc,
                        box_id: i.box_id,
                        food_box_money: i.food_box_money,
                        price: i.price,
                        buy_num: i.buy_num,
                        open_discount: i.open_discount,
                        current: i.current,
                        money: i.money
                    });
                });
                var car_list = JSON.stringify(tmpcar);
                
                
                var param ={
                    category_list : categoryList,
                    open_id       : this.openId,
                    car_list     : car_list,
                    store_id      : this.storeId
                    
                }
               // $api_base.post_zjd($api_base.saveCartInfo,param,1).then(function(res) {
                    // if(res){
                    //     let data = res.data;
                    //     console.log(data.msg);
                    // } 
               // });
            }
        },
        onReachBottom: function () {
            if(this.tabbarId == 3){
                var pn = this.evalPage;
                var pc = this.evalLimit;
                var count = this.eval_list.length;
                if (pn * pc <= count) {
                    this.evalPage++
                    this.loadEvaluation(true);
                } else {
                    this.noMore = true;
                }
            } 
        },
        onHide: function(){
            if(this.carList.length>0)
                this.saveInfo();
        },
        onUnload: function(){
            if(this.carList.length>0)
                this.saveInfo();
        }
    }
</script>
<style>
  page {
  background-color: #fff;
  }
</style>
<style lang="scss" scoped>
	@import 'index.scss';
</style>
